Instructions for processing of several nodes can be specified in one template.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:apply-templates select="aaa"/> </xsl:template> <xsl:template match="aaa"> <xxx> <xsl:apply-templates/> </xxx> </xsl:template> <xsl:template match="bbb|ccc"> <z1> <xsl:text>(</xsl:text> <xsl:value-of select="."/> <xsl:text>)</xsl:text> </z1> </xsl:template> <xsl:template match="ddd|eee"> <z2> <xsl:text>-- </xsl:text> <xsl:value-of select="."/> <xsl:text> --</xsl:text> </z2> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <bbb>B</bbb> <ccc>C</ccc> <ddd>D</ddd> <eee>E</eee> </aaa> |
Output
<xxx> <z1>(B)</z1> <z1>(C)</z1> <z2>-- D --</z2> <z2>-- E --</z2> </xxx> |
| Previous chapter: | - - - |
| Next chapter: | Sequences |
| Previous page: | Current position |
| Next page: | Selection of all child elements or all attributes of an element |