XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – round two / Creating nodes / Creating attribute nodes with xsl:attribute
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 2.)
The instruction xsl:attribute creates an attribute node whose name can be determined dynamically through its name attribute. The newly created attribute obtains its value from the template-block inside the instruction or, as here, from the result of its select attribute:
<beispiel>
<xsl:attribute name="attributname" select="'attributwert'"/>
</beispiel>
produces:
<beispiel attributname="attributwert"/>The instruction generally applies to an element node that is output at the same time. This is done either using the subsequently described xsl:copy, with xsl:element or by outputting a literal result element. In the result sequence, the attribute node must precede any child nodes of this element; otherwise, a serialization error occurs. If the element already has an attribute with the same name, xsl:attribute overwrites the old attribute value.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn