XPath Kick Start: Navigating XML with XPath 1.0 and 2.0

  • You use XSLT to manipulate, extract, and format data from XML documents. Using XSLT, you don't have to resort to creating your own XML processors. XSLT itself is a specification of W3C, and has been a recommendation since November 16, 1999. You can find the W3C recommendation for XSLT 1.0 at www.w3.org/TR/xslt.

  • XSLT has its own syntax, and this chapter's work was dedicated to learning that syntax. You use that syntax in XSLT stylesheets, which starts with an XML declaration and the element <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> .

  • XSLT stylesheets are made up of templates that match the nodes you want to work with. As we saw in this chapter, you use the match attribute in the <xsl:template> element to match nodes. You can also select the value of nodes using the <xsl:value-of> element, setting the select attribute to the XPath expression you want to use. The <xsl:for-each> element lets you work with multiple nodes. This element will let you loop over multiple nodes in a node-set.

  • There are two different XSLT attributes you use in XSLT elements and can assign XPath expressions tothe match and the select attributes. Specifically, the match attribute appears in the <xsl:template> element, and the select attribute appears in the <xsl:apply-templates> , <xsl:value-of> , <xsl:for-each> , <xsl:copy-of> , and <xsl: sort > XSLT elements. The match attribute can only handle the self or child axis (although XPath expressions in the predicate can use any axis), and there is no restriction on the XPath expressions you can assign to the select attribute.

  • You can use the <xsl:copy> element to make a shallow copy of nodes, and the <xsl:copy-of> element lets you create deep copies. And the <xsl:if> and <xsl:choose> elements let you make choices in your XSLT stylesheets.

  • Handling whitespace in XSLT and understanding the default XSLT rules are important if you want to create your own templates. In particular, it's important to realize that if you don't provide any rule to the contrary, the parsed character data in the source document will be inserted into the result document.

Категории