Nic Miloslav Example 57 | KEYWORDS EXAMPLES AUTHORS |
---|
Function generate-id generates id conforming to XML spec. Stylesheet 2 uses this function to add id to all elements in source XML.
XML | HOME XSL 1 XSL 2 |
---|
<xslTutorial > |
<AAA name='top'> |
<BBB pos='1' val='bbb'>11111</BBB> |
<BBB>22222</BBB> |
</AAA> |
<AAA name='bottom'> |
<BBB>33333</BBB> |
<BBB>44444</BBB> |
</AAA> |
</xslTutorial> |
XSL 1 | HOME XML HTML 1 OUTPUT 1 |
---|
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> |
<xsl:template match="/"> |
<DIV><B><xsl:text> generate-id(//AAA) : </xsl:text> </B> |
<xsl:value-of select="generate-id(//AAA) "/></DIV> |
<DIV><B><xsl:text> generate-id(//BBB) : </xsl:text> </B> |
<xsl:value-of select="generate-id(//BBB) "/></DIV> |
<DIV><B><xsl:text> generate-id(//AAA[1]) : </xsl:text> </B> |
<xsl:value-of select="generate-id(//AAA[1]) "/></DIV> |
<DIV><B><xsl:text> generate-id(//*[1]) : </xsl:text> </B> |
<xsl:value-of select="generate-id(//*[1]) "/></DIV> |
<DIV><B><xsl:text> generate-id(//xslTutorial/*[1]) : </xsl:text> </B> |
<xsl:value-of select="generate-id(//xslTutorial/*[1]) "/></DIV> |
</xsl:template> |
</xsl:stylesheet> |
HTML 1 | HOME XML XSL 1 OUTPUT 1 |
---|
<DIV> |
<B>generate-id(//AAA) : </B>N3</DIV> |
<DIV> |
<B>generate-id(//BBB) : </B>N6</DIV> |
<DIV> |
<B>generate-id(//AAA[1]) : </B>N3</DIV> |
<DIV> |
<B>generate-id(//*[1]) : </B>N1</DIV> |
<DIV> |
<B>generate-id(//xslTutorial/*[1]) : </B>N3</DIV> |
OUTPUT 1 | HOME XML XSL 1 HTML 1 |
---|
XSL 2 | HOME XML HTML 2 OUTPUT 2 |
---|
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> |
<xsl:template match="*"> |
<xsl:copy select="."> |
<xsl:attribute name="id"> |
<xsl:value-of select="generate-id()"/> |
</xsl:attribute> |
<xsl:for-each select="@*"> |
<xsl:attribute name="{name()}"> |
<xsl:value-of select="."/> |
</xsl:attribute> |
</xsl:for-each> |
<xsl:apply-templates/ > |
</xsl:copy> |
</xsl:template> |
</xsl:stylesheet> |
HTML 2 | HOME XML XSL 2 OUTPUT 2 |
---|
<xslTutorial id="N1"> |
<AAA id="N3" name="top"> |
<BBB id="N6" pos="1" val="bbb">11111</BBB> |
<BBB id="N11">22222</BBB> </AAA> |
<AAA id="N15" name="bottom"> |
<BBB id="N18">33333</BBB> |
<BBB id="N21">44444</BBB> </AAA> </xslTutorial> |
OUTPUT 2 | HOME XML XSL 2 HTML 2 |
---|