9
XSLT Introduction

XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

Embed Size (px)

Citation preview

Page 1: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

XSLT Introduction

Page 2: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

XSLT is the transformation part of XSL

• An XSLT file contains rules which are applied against and XML file to produce an output

• Outputs are typically:– Reformatted/rearranged XML files

– HTML files which display the XML data

– Other text files

Page 3: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

XSLT rules are specified as follows:

• XSLT files are XML files (they comply with the the XML specification)

• Each XSLT rule is, therefore, expressed by an XML tag in this general format

<tag-name attribute> The result as data

</tag-name>

The rules are also known as “templates”

Page 4: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

XSLT rules continued…

• There is one apparent exception to this format:

• The “result data” (body of the tag) may include other tags representing other XSLT instructions

• Think of these instructions as “subroutines” processed exactly as subroutines (or methods) are. That is to say, that the subroutine does it’s job and control returns to the instructions immediately following the call.

• To learn XSLT transformation, therefore, is to learn the various rules, how each works and how to apply them

Page 5: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

XSLT rules continued…

• The templates are thus applied in a series of nested loops

• There are no “goto” or “branching” instructions

• There are looping instructions, if … statements and a case-like structure

• Variables exist but there are some restrictions on their use

Page 6: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

<xsl: apply-templates />

• Applies the templates of each child of the current node

• Note that there is no selection involved, it applies the template for every node

Page 7: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

<xsl:template match=“value” />

• Matches the value specified in the match attribute to the names of the tags in the input xml file

• The body of the tag specifies the processing appropriate for each instance of the matching tag

Page 8: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs

<xsl:value-of select=“value” />

• Causes the data associated with the XML file tag whose name matches value to be output

• If the value starts with an ‘@’ (as in @xxx) then xxx is matched to an attribute rather than a tag-name

• If the value is in the form ‘yyy/@xxx’ then xxx is matched to an attribute belonging to tag-name yyy

• If the value is “.” the ‘.’ refers to the data value of the current tag

• If the value is ./@xxx the data is the value of the xxx attribute of the current tag

Page 9: XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs