If star "*" is used instead of element names, all names of elements are matched. Similarly, "@*" matches all attribute nodes.
Function name() returns name of currently processed elements or attributes.
|
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 select="*"/> </xxx> <yyy> <xsl:apply-templates select="@*"/> </yyy> </xsl:template> <xsl:template match="*"> <z1> <xsl:value-of select="name()"/> <xsl:text>: </xsl:text> <xsl:value-of select="."/> </z1> </xsl:template> <xsl:template match="@*"> <z2> <xsl:value-of select="name()"/> <xsl:text>: </xsl:text> <xsl:value-of select="."/> </z2> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa p="1" r="2" s="3"> <bbb>B</bbb> <ccc>C</ccc> <ddd>D</ddd> </aaa> |
Output
<xxx> <z1>bbb: B</z1> <z1>ccc: C</z1> <z1>ddd: D</z1> </xxx> <yyy> <z2>p: 1</z2> <z2>r: 2</z2> <z2>s: 3</z2> </yyy> |
| Previous chapter: | - - - |
| Next chapter: | Sequences |
| Previous page: | Shared templates for several elements |
| Next page: | Template priorities |