XSLT <xsl:apply-templates> Element
Het element <xsl:apply-templates> past een sjabloonregel toe op het huidige element of op de onderliggende knooppunten van het huidige element.
Het element <xsl:apply-templates>
Het element <xsl:apply-templates> past een sjabloon toe op het huidige element of op de onderliggende knooppunten van het huidige element.
Als we een "select" attribuut toevoegen aan het <xsl:apply-templates> element, zal het alleen de onderliggende elementen verwerken die overeenkomen met de waarde van het attribuut. We kunnen het "select" attribuut gebruiken om aan te geven in welke volgorde de onderliggende nodes moeten worden verwerkt.
Bekijk het volgende XSL-stijlblad:
Voorbeeld
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>