[Home]XSLT

ec2-3-230-143-213.compute-1.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic

eXstensible Stylesheet Language Transformation

The transforming bit of XSL?. (The remainder is XSL-FO - a specific markup language for print, I think.)

It is an XML dialect, for specifying the transformation of XML documents into XML, HTML or arbitrary text documents. Interpreters include Saxon, and quite likely your web browser.

It is almost a FunctionalProgrammingLanguage, except that the equivalent of functions, templates, are not first class objects. There are strictly no side-effects to an XSL transformation.
To clarify that, XSLT uses XPath expressions, which have no way to refer to templates. You can invoke XPath functions in an XPath expression. There is a non-standard extension in Saxon (and maybe some other processors) which lets you declare functions in XSLT with an equivalent syntax to named templates, which can then be used in XPath expressions.

Example:




<xsl:stylesheet version="1.0">

<xsl:template match="item">
<div class="item">
<div class="header"><xsl:apply-templates select="title" /></div>
<div class="content"><xsl:apply-templates select="content" /></div>
</div>
</xsl:template>

<xsl:template match="emph">
<em>
<xsl:apply-templates />
</em>
</xsl:template>

<!-- catch-all to copy and process otherwise-unmatched nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>



translates this:

<item>
<title>Introduction</title>
<content>Welcome to this <emph>thing</emph></content>
</item>

into this:

<div class="item">
<div class="header">Introduction</div>
<div class="content">Welcome to this thing</div>
</div>



CategoryComputing

ec2-3-230-143-213.compute-1.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic
Edit this page | View other revisions | Recently used referrers
Last edited July 17, 2007 2:04 pm (viewing revision 2, which is the newest) (diff)
Search: