|
|
|
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:
<xsl:value-of select=”Emp_Id”/>
or
<xsl:value-of select=”Employee-Detail/
Employee/Emp_Id”/> |
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.
<xsl:for-each select=”Employee”>
<xsl:value-of select=”Emp_Id”/>
<xsl:value-of select=”Emp_Name”/>
</xsl:for-each> |
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
display.
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 |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
Download PDF |
|
|
|
|
|
|
|
|
|