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.

   

back to top