|
|
XSLT: The XML transformation language By Ragageethika
Contents What is XSLT XSL Vs HTML XSL Elements XSL Transformations Demos
The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based Style sheet Language. XSLT = XSL Transformations and 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. Normally XSLT does this by transforming each XML element into an HTML element. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree. What is XSLT
XSL stands for Extensible Style sheet Language. CSS is TML Style Sheets HTML uses predefined tags and the meaning of the tags are XSL = XML Style Sheets CSS does not support operations such as reordering and sorting elements based on a condition, and displaying only selective elements. 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 Vs HTML
Example.2
xsl:Template indicates that there are child nodes/subdirectories. Syntax: <Xsl:Template match=“/ “ ></ Xsl:Template> 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 Syntax : <xsl:value-of select=“CD”></xsl:value-of> xsl:for-each element allows you to do looping in XSLT. It can be used to select every XML element of a specified node-set: Syntax : <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> XSL Elements
Legal filter operators are: = (equal) != (not equal) < less than > greater than Syntax: <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> Xsl:sort element is used to sort the output ,where to put the Sort information Syntax: <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td> <xsl:value-of select="title"/></td> </xsl:for-each> XSL Elements
xsl:if element is used put a conditional if test against the content of the XML file, Syntax: <xsl:if test="expression"> Statements</xsl:if> <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td><xsl:if test="price > 10"/> </td> <tr> </xsl:sort> </xsl:for-each> XSL Elements
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"> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="price > 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> XSL Elements
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 can use the select attribute to specify the order in which the child nodes are processed. XSL Elements
Where does the XML transformation happen? There are three primary ways to transform XML documents into other formats, such as HTML, with an XSLT style sheet: 1. The XML document and associated style sheet are both served to the client (Web browser), which then transforms the document as specified by the style sheet and presents it to the user. 2. The server applies an XSLT style sheet to an XML document to transform it to some other format (generally HTML) and sends the transformed document to the client (Web browser). 3. A third program transforms the original XML document into some other format (often HTML) before the document is placed on the server. Both server and client only deal with the transformed document.
References www.w3schools.com ---- Learn XSLT
| URL: |
No comments posted yet
Comments