Chapter 6. Building New XML Documents with XSLT

  • Creating new XML elements

  • <xsl:element>

  • <xsl:attribute>

  • Literal result elements (LREs)

  • Attribute value templates (AVTs)

  • <xsl:processing-instruction>

  • <xsl:comment>

  • <xsl:namespace-alias>

One of the most convenient features of XSLT stylesheets is the ability to generate new content in the process of transformation. This generated content can be derived through a series of XPath expressions in combination with LREs, text that you add, or with other elements in XSLT yet to be introduced.

There are many ways to work with the existing structure and content of an XML document. However, there are only a few specific XSLT elements that deal directly with the creation of new elements and content. In this chapter, we will look at how content can be created using LREs, as well as the following XSLT elements: <xsl:element>, which is used to generate new XML elements; <xsl:attribute>, which is used to generate new XML attributes; <xsl:attribute-set>, which is used to create a group of attributes; and <xsl:text>, which is used to generate text. We will also discuss attribute value templates (AVTs), which provide the capability to use expressions in attributes. At the end of this chapter, we will also discuss two elements that are used to generate processing-instructions and comments. Finally, the last section will discuss the use of the <xsl:namespace-alias> element, which is useful when generating namespaced elements using LREs.

There are two specific ways to add new elements: either using LREs or using the <xsl:element> element. While both methods generate new elements, there are some specific nuances that may make one method preferable over the other, depending on the circumstances. Specifically, dealing with namespaces and attributes may be easier using <xsl:element> rather than LREs. Both methods are presented in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset