Nic Miloslav Example 11 | KEYWORDS EXAMPLES AUTHORS |
---|
The xsl:copy element may have a use-attribute-sets attribute. In this way attributes for copied element can be specified. Stylesheet 2 does not work as expected (setting use-attribute-sets with name function)., because expresions in attributes that refer to named XSLT objects are not evaluated. Look at Example 31 for more details.
XML | HOME XSL 1 XSL 2 |
---|
<xslTutorial > |
<H1>GREETING</H1> |
<P>Hello, world!</P> |
</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="/"> |
<xsl:apply-templates select="/xslTutorial/*"/> |
</xsl:template> |
<xsl:template match="H1"> |
<xsl:copy use-attribute-sets='H1'> |
<xsl:value-of select="."/> |
</xsl:copy> |
</xsl:template> |
<xsl:template match="P"> |
<xsl:copy use-attribute-sets='P '> |
<xsl:value-of select="."/> |
</xsl:copy> |
</xsl:template> |
<xsl:attribute-set name="H1"> |
<xsl:attribute name='align'>center</xsl:attribute> |
<xsl:attribute name='style'>color:red</xsl:attribute> |
</xsl:attribute-set> |
<xsl:attribute-set name="P"> |
<xsl:attribute name='align'>left</xsl:attribute> |
<xsl:attribute name='style'>color:blue</xsl:attribute> |
</xsl:attribute-set> |
</xsl:stylesheet> |
HTML 1 | HOME XML XSL 1 OUTPUT 1 |
---|
<HTML> |
<HEAD> </HEAD> |
<BODY> |
<H1 align="center" style="color:red">GREETING</H1> |
<P align="left" style="color:blue">Hello, world!</P> </BODY> </HTML> |
OUTPUT 1 | HOME XML XSL 1 HTML 1 |
---|
Hello, world!
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:apply-templates select="/xslTutorial/*"/> |
</xsl:template> |
<xsl:template match="*"> |
<xsl:copy use-attribute-sets='{name(.)}'> |
<xsl:value-of select="."/> |
</xsl:copy> |
</xsl:template> |
<xsl:attribute-set name="H1"> |
<xsl:attribute name='align'>center</xsl:attribute> |
<xsl:attribute name='style'>color:red</xsl:attribute> |
</xsl:attribute-set> |
<xsl:attribute-set name="P"> |
<xsl:attribute name='align'>left</xsl:attribute> |
<xsl:attribute name='style'>color:blue</xsl:attribute> |
</xsl:attribute-set> |
</xsl:stylesheet> |
HTML 2 | HOME XML XSL 2 OUTPUT 2 |
---|
<HTML> |
<HEAD> </HEAD> |
<BODY> |
<H1>GREETING</H1> |
<P>Hello, world!</P> </BODY> </HTML> |
OUTPUT 2 | HOME XML XSL 2 HTML 2 |
---|
Hello, world!