W naszym labie działają takie polecenia:
java org.apache.xalan.xslt.Process -XSL szablon.xsl -IN wejscie.xml -OUT wynik.html
xsltproc -o wynik.html szablon.xsl wejscie.xml
Szablony nazwane stanowią konstrukcję analogiczną do funkcji i umożliwiają "normalne" programowanie.
<xsl:template name="wiersz">
<!-- Parametry formalne -->
<xsl:param name="tytul" select="Wiersz tabeli:"/>
<xsl:param name="kolumny"/>
<!-- Treść szablonu ("ciało funkcji") -->
<tr><th><xsl:value-of select="$tytul"/></th>
<xsl:for-each select="$kolumny">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:template>
<!-- ... -->
<!-- Wywołanie gdzieś w treści innego szablonu -->
<table>
<xsl:for-each select="/lista-sklepow/sklep[$i]/towar">
<xsl:call-template name="wiersz">
<!-- Parametry aktualne -->
<xsl:with-param name="tytul" select="nazwa-towaru"/>
<xsl:with-param name="kolumny" select="./*[position() > 1]"/>
</xsl:call-template>
</xsl:for-each>
</table>
XSLT jest też XML-em, a więc może być wyprodukowany jako wynik XSLT. Trzeba zrobić coś, żeby odróżnić elementy, ktróre mają być interpretowane jako XSLT, od elementów, które mają być wynikiem transormacji. Umożliwia to element namespace-alias.
Przykład z rekomendacji:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
<xsl:template match="/">
<axsl:stylesheet>
<xsl:apply-templates/>
</axsl:stylesheet>
</xsl:template>
<xsl:template match="block">
<axsl:template match="{.}">
<fo:block><axsl:apply-templates/></fo:block>
</axsl:template>
</xsl:template>
</xsl:stylesheet>
przykład silnia
przykład towary
przykład tabela