You are on page 1of 29

VB.

NET & XML

Unit 12

Unit 12
Structure: 12.1 Introduction Objectives 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 XSLT XSLT Browsers

XSL (XML Style sheet Language)

Correct Style Sheet Declaration XSLT <xsl:template> XSLT <xsl:value-of> Element XSLT <xsl:for-each> Element Filtering the Output XSLT <xsl:sort> Element

12.10 XSLT <xsl:if> Element 12.11 XSLT <xsl:choose> Element 12.12 XSLT <xsl:apply-templates> Element 12.13 XPath 12.14 Summary 12.15 Terminal Questions

12.1 Introduction
XSL stands for Extensible Stylesheet Language. XSL markup language is used to transform data from one markup language to other. XSLT (XSL Transformation Engine) is an implementation of XSL markup language. The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based Stylesheet Language.

Sikkim Manipal University

Page No. 227

VB.NET & XML

Unit 12

CSS = HTML Style Sheets HTML uses predefined tags and the meanings of the tags are well understood. The <table> element in HTML defines a table - and a browser knows how to display it. Adding styles to HTML elements is simple. Telling a browser to display an element in a special font or color is easy with CSS. XSL = XML Style Sheets XML does not use predefined tags (we can use any tag-names we like), and the meaning of these tags are not well understood. A <table> element could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it. XSL describes how the XML document should be displayed! XSL - More Than a Style Sheet Language XSL consists of three parts:

XSLT - a language for transforming XML documents XPath - a language for navigating in XML documents XSL-FO - a language for formatting XML documents

Objectives XSL is the Extensible Stylesheet Language. XSL transforms and translates XML data from one XML format into another. Consider, for example, that the same XML document may need to be displayed in HTML, PDF, and Postscript form. Without XSL, the XML document would have to be manually duplicated, and then converted into each of these three formats. Instead, XSL provides a mechanism of defining stylesheets to accomplish these types of tasks. Rather than having to change the data because of a different representation, XSL provides a complete separation of data, or
Sikkim Manipal University Page No. 228

VB.NET & XML

Unit 12

content, and presentation. If an XML document needs to be mapped to another representation, then XSL is an excellent solution. It provides a method comparable to writing a Java program to translate data into a PDF or HTML document, but supplies a standard interface to accomplish the task. To perform the translation, an XSL document can contain formatting objects. These formatting objects are specific named tags that can be replaced with appropriate content for the target document type. A common formatting object might define a tag that some processor uses in the transformation of an XML document into PDF; in this case, the tag would be replaced by PDF specific information. Formatting objects are specific XSL instructions, and although we will lightly discuss them, they are largely beyond the scope of this book. Instead, we will focus more on XSLT, a completely text-based transformation process. Through the process of XSLT (Extensible Style sheet Language Transformation), an XSL textual style sheet and a textual XML document is "merged" together, and what results is the XML data formatted according to the XSL stylesheet.

12.2 XSLT
What is XSLT?

XSLT stands for XSL Transformations XSLT is the most important part of XSL XSLT transforms an XML document into another XML document XSLT uses XPath to navigate in XML documents XSLT is a W3C Recommendation

XSLT = XSL Transformations: XSLT is the most important part of XSL. XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an XHTML element. With XSLT you can add/remove elements and
Sikkim Manipal University Page No. 229

VB.NET & XML

Unit 12

attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree. XSLT Uses XPath: XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents.

12.3 XSLT Browsers


Nearly all major browsers have support for XML and XSLT. Mozilla Firefox: As of version 1.0.2, Firefox has support for XML and XSLT (and CSS). Mozilla: Mozilla includes Expat for XML parsing and has support to display XML + CSS. Mozilla also has some support for Namespaces. Mozilla is available with an XSLT implementation. Netscape: As of version 8, Netscape uses the Mozilla engine, and therefore it has the same XML / XSLT support as Mozilla. Opera: As of version 9, Opera has support for XML and XSLT (and CSS). Version 8 supports only XML + CSS. Internet Explorer: As of version 6, Internet Explorer supports XML, Namespaces, CSS, XSLT, and XPath. Version 5 is NOT compatible with the official W3C XSL Recommendation.

12.4 Correct Style Sheet Declaration


The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>.

Sikkim Manipal University

Page No. 230

VB.NET & XML

Unit 12

Note: <xsl:stylesheet> and <xsl:transform> are completely synonymous and either can be used! The correct way to declare an XSL style sheet according to the W3C XSLT Recommendation is: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> (or) <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> To get access to the XSLT elements, attributes and features we must declare the XSLT namespace at the top of the document. The xmlns:xsl="http://www.w3.org/1999/XSL/Transform" points to the official W3C XSLT namespace. If you use this namespace, you must also include the attribute version="1.0". Start with a Raw XML Document We want to transform the following XML document ("cdcatalog.xml") into XHTML: <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd> <title>JAVA</title> <artist>Balaguruswamy</artist> <country>India</country> <company>Hyderabad</company> <price>100.00</price> <year>1990</year> </cd> <cd>
Sikkim Manipal University Page No. 231

VB.NET & XML

Unit 12

<title>java</title> <artist>schild</artist> <country>AP</country> <company>Madras</company> <price>120.00</price> <year>2000</year> </cd> </catalog> Viewing XML Files in Fire fox and Internet Explorer: Open the XML file (typically by clicking on a link) - The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the element structure. To view the raw XML source (without the + and - signs), select "View Page Source" or "View Source" from the browser menu. Viewing XML Files in Netscape 6: Open the XML file, then right-click in XML file and select "View Page Source". The XML document will then be displayed with color-coded root and child elements. Viewing XML Files in Opera 7: Open the XML file, then right-click in XML file and select "Frame" / "View Source". The XML document will be displayed as plain text. Create an XSL Style Sheet: Then you create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body>
Sikkim Manipal University Page No. 232

VB.NET & XML

Unit 12

<h2>My Books Collection</h2> <table border="1"> <tr bgcolor="red"> <th align="left">Title</th> <th align="left">Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Link the XSL Style Sheet to the XML Document Add the XSL style sheet reference to your XML document ("cdcatalog.xml"): <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> <catalog> <cd> <title>JAVA</title> <artist>Balaguruswamy</artist> <country>India</country> <company>Hyderabad</company> <price>100.00</price> <year>1990</year>
Sikkim Manipal University Page No. 233

VB.NET & XML

Unit 12

</cd> <cd> <title>java</title> <artist>schild</artist> <country>AP</country> <company>Madras</company> <price>120.00</price> <year>2000</year> </cd> </catalog> If you have an XSLT compliant browser it will nicely transform your XML into XHTML. The details of the example above will be explained in the next sections.

12.5 XSLT <xsl:template> Element


An XSL style sheet consists of one or more set of rules that are called templates. A template contains rules to apply when a specified node is matched. The <xsl:template> Element. The <xsl:template> element is used to build templates. The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document). Ok, let's look at a simplified version of the XSL file from the previous section: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Sikkim Manipal University Page No. 234

VB.NET & XML

Unit 12

<xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr> <td>,</td> <td>,</td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet> Since an XSL style sheet is an XML document itself, it always begins with the XML declaration: <?xml version="1.0" encoding="ISO-8859-1"?>. The next element, <xsl:stylesheet>, defines that this document is an XSLT style sheet document (along with the version number and XSLT namespace attributes). The <xsl:template> element defines a template. The match="/" attribute associates the template with the root of the XML source document. The content inside the <xsl:template> element defines some HTML to write to the output.

Sikkim Manipal University

Page No. 235

VB.NET & XML

Unit 12

The last two lines define the end of the template and the end of the style sheet. The result of the transformation above will look like this: My Books Collection Title , Artist ,

The result from this example was a little disappointing, because no data was copied from the XML document to the output. In the next section you will learn how to use the <xsl:value-of> element to select values from the XML elements.

12.6 XSLT <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: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr>
Sikkim Manipal University Page No. 236

VB.NET & XML

Unit 12

<td><xsl:value-of select="catalog/cd/title"/></td> <td><xsl:value-of select="catalog/cd/artist"/></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet> 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 result of the transformation above will look like this: My Books Collction Title JAVA Artist Balaguruswamy

The result from this example was also a little disappointing, because only one line of data was copied from the XML document to the output. In the next section you will learn how to use the <xsl:for-each> element to loop through the XML elements, and display all of the records.

12.7 XSLT <xsl:for-each> Element


The <xsl:for-each> element allows you to do looping in XSLT. The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Sikkim Manipal University Page No. 237

VB.NET & XML

Unit 12

<xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> 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 result of the transformation above will look like this: My Books Collection Title JAVA Java Artist Balaguruswamy Schild
Page No. 238

Sikkim Manipal University

VB.NET & XML

Unit 12

12.8 Filtering the Output


We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> Legal filter operators are:

= (equal) != (not equal) &lt; less than &gt; greater than

Take a look at the adjusted XSL style sheet: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table>
Sikkim Manipal University Page No. 239

VB.NET & XML

Unit 12

</body> </html> </xsl:template> </xsl:stylesheet> The result of the transformation above will look like this: My Books Collection Title JAVA Artist Balaguruswamy

12.9 XSLT <xsl:sort> Element


The <xsl:sort> element is used to sort the output. Where do you put the Sort Information? To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr>
Sikkim Manipal University Page No. 240

VB.NET & XML

Unit 12

<td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Note: The select attribute indicates what XML element to sort on. The result of the transformation above will look like this: My Books Collection Title JAVA Java Artist Balaguruswamy Schild

12.10 XSLT <xsl:if> Element


To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document. Syntax <xsl:if test="expression"> ... ...some output if the expression is true... ... </xsl:if> Where to Put the <xsl:if> Element: To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file: <?xml version="1.0" encoding="ISO-8859-1"?>
Sikkim Manipal University Page No. 241

VB.NET & XML

Unit 12

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:if test="price &gt; 10"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Note: The value of the required test attribute contains the expression to be evaluated. The code above will only output the title and artist elements of the CDs that has a price that is higher than 10. The result of the transformation above will look like this:
Sikkim Manipal University Page No. 242

VB.NET & XML

Unit 12

My Books Collection Title JAVA Java Artist Balaguruswamy Schild

12.11 XSLT <xsl:choose> Element


The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests. Syntax: <xsl:choose> <xsl:when test="expression"> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise> </xsl:choose> Where to put the Choose Condition To insert a multiple conditional test against the XML file, add the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1">
Sikkim Manipal University Page No. 243

VB.NET & XML

Unit 12

<tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price &gt; 10"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> The code above will add a pink background-color to the "Artist" column WHEN the price of the CD is higher than 10.

Sikkim Manipal University

Page No. 244

VB.NET & XML

Unit 12

The result of the transformation will look like this: My Books Collection Title JAVA Java Artist Balaguruswamy Schild

View the XML file, View the XSL file, and View the result Another Example Here is another example that contains two <xsl:when> elements: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price &gt; 10"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:when test="price &gt; 9">
Sikkim Manipal University Page No. 245

VB.NET & XML

Unit 12

<td bgcolor="#cccccc"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> The code above will add a pink background color to the "Artist" column WHEN the price of the CD is higher than 10, and a grey background-color WHEN the price of the CD is higher than 9 and lower or equal to 10. The result of the transformation will look like this: My Books Collection Title JAVA Java Artist Balaguruswamy Schild

View the XML file, View the XSL file, and View the result

12.12 XSLT <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:apply-templates> element it will process only the child element that matches the value of the attribute. We
Sikkim Manipal University Page No. 246

VB.NET & XML

Unit 12

can use the select attribute to specify the order in which the child nodes are processed. This element is evaluated in two steps: Step1: Locates the nodes from input xml document using the specified pattern. Step2: Evaluates the respective template for each of the selected node. While preparing a pattern we can use the following special characters: . (Dot): Describes the node for which this template/enclosing element is being evaluated. . . (Dot Dot): Describes the parent node of the current node. * (star): Describes all the child nodes. //: Describes the document node, this is used to specify the absolute node path. | (single pipe character): Describes or. NOTE: If a select attribute is not specified then it defaults to * i.e. it selects all the child nodes of the current node. Look at the following XSL style sheet: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My Books Collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template>
Sikkim Manipal University Page No. 247

VB.NET & XML

Unit 12

<xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> <xsl:template match="title"> Title: <span style="color:#ff0000"> <xsl:value-of select="."/></span> <br /> </xsl:template> <xsl:template match="artist"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template> </xsl:stylesheet> The result of the transformation will look like this: My Books Collection Title: JAVA Artist: Balaguruswamy Title:Java Artist: Schild

12.13 XPath
XPath specification is a part of xml specification XPath specifications include some constructs to build paths, expressions and include some functions for string and operations. These specifications can be used in XSL.
Sikkim Manipal University Page No. 248

VB.NET & XML

Unit 12

XPath is a major element in XSLT XPath is a W3C recommendation XPath Nodes In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XPath Axes This part of the XPath specifications includes keywords and functions that allow to build paths to locate nodes in an xml document. The XML Example Document We will use the following XML document in the examples below. <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore>

Sikkim Manipal University

Page No. 249

VB.NET & XML

Unit 12

An axis defines a node-set relative to the current node.


AxisName ancestor ancestor-or-self attribute child descendant descendant-or-self Result Selects all ancestors (parent, grandparent, etc.) of the current node Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself Selects all attributes of the current node Selects all children of the current node Selects all descendants (children, grandchildren, etc.) of the current node Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself Selects everything in the document after the closing tag of the current node Selects all siblings after the current node Selects all namespace nodes of the current node Selects the parent of the current node Selects everything in the document that is before the start tag of the current node Selects all siblings before the current node Selects the current node

following following-sibling namespace parent preceding preceding-sibling self

Location Path Expression A location path can be absolute or relative. An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases the location path consists of one or more steps, each separated by a slash: An absolute location path: /step/step/... A relative location path: step/step/... Each step is evaluated against the nodes in the current node-set.

Sikkim Manipal University

Page No. 250

VB.NET & XML

Unit 12

A step consists of:

an axis (defines the tree-relationship between the selected nodes and the current node)

a node-test (identifies a node within an axis) zero or more predicates (to further refine the selected node-set)

The syntax for a location step is: axisname::nodetest[predicate] Examples


Example child::book attribute::lang child::* attribute::* child::text() child::node() descendant::book ancestor::book ancestor-or-self::book Result Selects all book nodes that are children of the current node Selects the lang attribute of the current node Selects all children of the current node Selects all attributes of the current node Selects all text child nodes of the current node Selects all child nodes of the current node Selects all book descendants of the current node Selects all book ancestors of the current node Selects all book ancestors of the current node and the current as well if it is a book node Selects all price grandchildren of the current node

child::*/child::price

XPath Operators An XPath expression returns either a node-set, a string, a Boolean, or a number. Below is a list of the operators that can be used in XPath expressions:
Sikkim Manipal University Page No. 251

VB.NET & XML

Unit 12

Operator |

Description Computes two nodesets Addition Subtraction Multiplication Division Equal Not equal Less than Less than or equal to Greater than Greater than or equal to or and Modulus remainder) (division

Example //book | //cd

Return value Returns a node-set with all book and cd elements 10 2 24 2 true if price is 9.80 false if price is 9.90 true if price is 9.90 false if price is 9.80 true if price is 9.00 false if price is 9.80 true if price is 9.00 false if price is 9.90 true if price is 9.90 false if price is 9.80 true if price is 9.90 false if price is 9.70 or true if price is 9.80 false if price is 9.50 true if price is 9.80 false if price is 8.50 1

+ * div = != < <= > >= or and mod

6+4 6-4 6*4 8 div 4 price=9.80 price!=9.80 price<9.80 price<=9.80 price>9.80 price>=9.80 price=9.80 price=9.70

price>9.00 and price<9.90 5 mod 2

XPath String functions: 1. substring(string,startindex,len) 2. substring-before(string1string2) Example: substring-before(abc,b) It returns a. 3. substring-after(string1string2) Example: substring-before(abc,b) It returns c.

Sikkim Manipal University

Page No. 252

VB.NET & XML

Unit 12

4. contains(string1,string2): Returns Boolean. This returns true if string2 appears in string1, otherwise false. 5. startwith(string1,string2); Example: startwith(abc,ab) It returns true. 6. string-length(string) : It returns the length of a string. 7. normalize-space (string): Returns the input string after normalizing the white space, which includes eliminating white spaces in beginning and ending and remove multiple white space identified in between of the string, replacing with a single white space. Example: - - abc - - xyz In the above the dashes (-) are white spaces. Output: abc-xyz

12.14 Summary
Use XSLT to transform XML documents into other formats, like XHTML. In this chapter we learned how to add/remove elements and attributes to or from the output file. We also learned how to rearrange and sort elements, perform tests and make decisions about which elements to hide and display. This tutorial has taught you how to find information in an XML document. We learned how to use XPath to navigate through elements and attributes in an XML document. We also learned how to use some of the standard functions that are built-in in XPath.

Sikkim Manipal University

Page No. 253

VB.NET & XML

Unit 12

12.15 Terminal Questions


1. What is XSLT and give the Correct Style Sheet Declaration? 2. Explain XSLT <xsl:template> and XSLT <xsl:value-of> with example. 3. Explain XSLT <xsl:value-of> and example. 4. Explain XSLT <xsl:sort> and XSLT <xsl:if> Element with example. 5. Explain XSLT <xsl:choose> and XSLT <xsl:apply-templates> Element with example. 6. What is XPath and explain XPath string functions with examples? XSLT <xsl:for-each> Element with

Sikkim Manipal University

Page No. 254

VB.NET & XML

Unit 12

References:

Sikkim Manipal University

Page No. 255

You might also like