Upload
clarence-greene
View
217
Download
0
Embed Size (px)
Citation preview
XSL – Extensible Style Sheet Language XSLT – XSL Transformations
› Used to transform XML documents to other formats ,like HTML or other XML documents
It uses XPATH to navigate thro XML docs
Elements and attributes can be added/removed from the document
XSLT uses XPATH to define parts of the source document that should match one or more predefined templates
When a match is found ,XSLT transforms the matching part of the source document into result document
Create an XSL Style Sheet
xsl:stylesheet is the root element
Link the Style sheet to XML document
<xsl:stylesheet version="1.0” xmlns:xsl="http://www.w3.org/1999/XSL/Transform”
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>”
Template consists of rules to apply when a matching node is found
xsl:template is used to build template The match attribute is used to associate
a template with an XML element. The value of the match attribute is an
XPath expression
Match=“/” is defines the whole document
<xsl:template match="/“>
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href=“name.xsl"?>
<program><btech> <name>Arun</name> <regno>10BIT001</regno> <cgpa>9</cgpa></btech>
</program>
<?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>Students Name List</h2> <table border=‘1’> <tr bgcolor=‘white’> <th>Name</th> <th>Register No</th> </tr> <xsl:for-each select=“program/btech”> <tr> <td><xsl:value-of select=name"/></td> <td><xsl:value-of select=“regno"/></td> </tr> </xsl:for-each> </table> </body> </html></xsl:template></xsl:stylesheet>
Save as Program.xml (top)Save as Name.xsl (right)
Open the program.xml file in a browser
Used to extract the value of a selected node
<td><xsl:value-of select=name"/></td> <td><xsl:value-of select=“regno"/></td>
Used for looping through XML document
<xsl:for-each select=“program/btech”> <tr> <td><xsl:value-of select=name"/></td> <td><xsl:value-of select=“regno"/></td> </tr> </xsl:for-each>
Used for conditional testing against the content of the XML document
<xsl:if test=“expression”> <!--content goes here-->
</xsl:if>
<xsl:for-each select=“program/btech”><xsl:if test=“cgpa > 9“> <tr> <td><xsl:value-of select=name"/></td> <td><xsl:value-of select=“regno"/></td> </tr></xsl:if></xsl:for-each>
Used for conditional testing against the content of the XML document
<xsl:if test=“expression”> <!--content goes here-->
</xsl:if>
<xsl:for-each select=“program/btech”><xsl:if test=“cgpa > 9“> <tr> <td><xsl:value-of select=name"/></td> <td><xsl:value-of select=“regno"/></td> </tr></xsl:if></xsl:for-each>
www.w3schools.com XSLT Reference by John W. Shipman