Java Reference
In-Depth Information
<Zip>21144</Zip>
<Engine>4-Cylinder</Engine>
<Transmission>5-Speed</Transmission>
<Price>4500</Price>
<OPTIONS>
AM_FM_Radio,
Cassette,
Power Windows,
Power Locks,
Air Conditioning,
Tilt Steering,
Power Steering,
ABS,
Moon Roof,
Bucket Seats
</OPTIONS>
</VehicleData>
Transforming the XML Using an XSL Stylesheet
Stylesheets are valid XML documents that contain a set of XSL commands used to transform a
document. XSL stylesheets start with the xsl:stylesheet declaration, which forms the root node of
the XML document. The stylesheet declaration consists of a version and namespace. The namespace
declares the stylesheet tag prefix and the URL of tag definitions, as shown here:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
</xsl:stylesheet>
The namespace prefix xsl: is used in the body of the XSL document to identify XSL processing
statements. Tags that are not prefixed with xsl: are simply copied to the output without being
processed, so you can embed HTML tags in the XSL stylesheet, and they will be sent to the output
stream unchanged.
XSLT is unlike conventional programming languages such as Java because XSLT is a rule-based,
declarative language. XSL rules define templates that specify how an XML document should be
processed. These template rules can be defined in any order.
XSL templates are used to select XML elements for processing using the match operator. Here's a
typical example of the use of the xsl:template tag:
<xsl:template match="VehicleData">
...
</xsl:template>
The argument of the match operator is defined using an XPath expression. XPath simply defines the
path to a child node in much the same way as a file path defines a path to a file. For example, to select
an entire document for processing, you can match the root node, using match="/". Alternatively, you can
match the document element tag, in this case 'VehicleData'.
Caution
The difference between matching the root node, defined with "/", and matching the
document node, defined in this case with " VehicleData ", is that the XPath to a
child node is different in each case. For example, if you match the root node, using
Search WWH ::




Custom Search