Before processing can begin, the part of the
XML document with the information to be copied
to the output must be selected with an XPath expression. The selected section of the
document is called a node and is normally
selected with the match operator.
In the above statements, the <xsl:template>
element defines a template. The match=”/”
attribute associates the template with the root
node of the XML source document. Another
approach is to match the document element (the element that includes the entire document).
The <xsl:apply-templates> Element
The <xsl:apply-templates> element applies a
template to the current element or to the
current element’s child nodes.
If we add a select attribute to the <xsl:applytemplates>
element it will process only the child
element that matches the value of the attribute.
We can use the select attribute to specify the
order in which the child nodes are processed.
The <xsl:value-of> Element
The <xsl:value-of> element can be used to
extract the value of an XML element and add it
to the output stream of the transformation.
For example, the given expression will select
the value of Emp_Id attribute of the specified
element and write to the output:
Note: The value of the select attribute is an
XPath expression. An XPath expression works
like navigating a file system; where a forward
slash (/) selects subdirectories.
The <xsl:for-each select=”elementName “> Element
The ‘for-each’ expression is a loop that processes the same instructions for these elements. The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set. For example, the given expression finds all ‘Employee’ elements in the ‘Employee-Detail’ element context using the XPath expression ‘Employee-Detail/ Employee’.
If the selected node contains all elements in
the root, all of the ‘Employee-Detail’ elements
will be selected.
Introduction to XSLT
Extensible Stylesheet Language
Transformations (XSLT) is an XML-based
language that transforms an XML documents
and generates output into a different format
such as HTML, XML or another type of
document that is recognized by a browser like
WML, and XHTML.
XSLT is an extension of XSL, which is a
stylesheet definition language for XML
With XSLT you can add/remove elements and
attributes to or from the output file. You can
also rearrange and sort elements, and make
decisions about which elements to hide and
XSLT uses XPath to find information in an XML
document. XPath is used to navigate through
elements and attributes in XML documents.
Mar 2008 | Java Jazz Up |13
|View All Topics
|All Pages of this Issue