XSLT Identity Transformation Example
Closed this issue · 0 comments
You may want to take a look at the example we did together in class on Monday of an XSLT identity transformation, to review how XSLT templates works. Here's our XSLT file that we used to transform the simple XML of Shakespeare's sonnets: https://github.com/ebeshero/DHClass-Hub/blob/master/Class-Examples/XSLT/Shakespeare_Sonnets/SonnetIDTransform.xsl
The source XML is here: https://raw.githubusercontent.com/ebeshero/DHClass-Hub/master/Class-Examples/XSLT/Shakespeare_Sonnets/shakesSonnets.xml
Let's look at this template rule for a review of what we talked about:
<xsl:template match="line">
<l n="{count(preceding-sibling::line) + 1}"><xsl:apply-templates/></l>
</xsl:template>
In this element, notice the @match
attribute on the <xsl:template match="line">
It is matching on each <line>
element in the Shakespeare's sonnets XML file.
The <xsl:template>
element is called a template rule. It will match on every line, and replace it with a different element, the <l>
element that we're constructing inside the template rule.
We are creating the <l>
element, and inside it we run <xsl:apply-templates>
to go and process whatever the descendants of the <line>
element are (the contents of the lines).
Try running this at home to review and experiment with the XSLT syntax. Open these files in oXygen and run the XSLT over the source XML. Try removing <xsl:apply-templates>
to see and remind yourself what it does.
Take a look at the attribute value template we made to create the @n
on the new <l>
we are creating. What is it doing? / How is it working? You can apply this on the homework.