Main Content

matlab.io.xml.transform.StylesheetSourceString Class

Namespace: matlab.io.xml.transform

XSL source string for transformation

Since R2021a

Description

Use an object of the matlab.io.xml.transform.StylesheetSourceString class to specify a string of XSL markup to use as the stylesheet for a transformation. You can provide a StylesheetSourceString object as the stylesheet input to the transform or transformToString method of a matlab.io.xml.transform.Transformer object.

The matlab.io.xml.transform.StylesheetSourceString class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

stylesheetSourceObj = matlab.io.xml.transform.StylesheetSourceString(markup) creates a matlab.io.xml.transform.StylesheetSourceString object with the String property set to the specified XSL markup.

example

Properties

expand all

XSL markup, specified as a string scalar or character vector.

Attributes:

GetAccess
public
SetAccess
public
GetObservable
true
SetObservable
true

Examples

collapse all

This example transforms the XML markup for countries and their capital cities into an HTML table. The example specifies the input stylesheet as a matlab.io.xml.transform.StylesheetSourceString object.

The examples uses the file capitals.xml.

<Countries>
    <Country><Name>Canada</Name><Capital>Ottawa</Capital></Country>
    <Country><Name>France</Name><Capital>Paris</Capital></Country>
    <Country><Name>Peru</Name><Capital>Lima</Capital></Country>
</Countries>

Create a StylesheetSourceString object, stylesheetObj, to contain the XSL markup for the transformation.

import matlab.io.xml.transform.*
txt = ['<?xml version="1.0"?>' ...
    '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' ...
    '<xsl:template match="/">' ...
    '<html><body><table><tr><th>Country</th><th>Capital</th></tr>' ...
    '<xsl:for-each select="Countries/Country"><tr><td>' ...
    '<xsl:value-of select="Name"/></td><td>' ...
    '<xsl:value-of select="Capital"/></td></tr>' ...
    '</xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>'];
stylesheetObj = StylesheetSourceString(txt);

Perform the transformation and provide stylesheetObj as the stylesheet, capitals.xml as the XML source, and capitals.html as the name of the output file.

transform(Transformer,"capitals.xml",stylesheetObj,"capitals.html");

Open capitals.html in a browser.

web("capitals.html")

Here is the HTML table:

Version History

Introduced in R2021a