Wednesday, August 18, 2010

XSLT

Text are from http://www.w3schools.com/xsl/


  • XSL stands for EXtensible Stylesheet Language.
  • CSS - Style Sheet for HTML
  • XSL - Style Sheet fot XML
  • XSL describes how the XML document should be displayed!

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

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
  • All major browsers have support for XML and XSLT.

XSLT - Transformation

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

<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">

example transformation 
Source xml file.


Source XSL Style Sheet file.
 

Result of transformation.
 


<xsl:template>

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).

example:
 



<xsl:value-of>

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:
 


<xsl:for-each>

The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set:
 

Filtering

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:sort>

The <xsl:sort> element is used to sort the output.



<xsl:if>

The <xsl:if> element is used to put a conditional test against the content of the XML file.


<xsl:choose>

The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests.




<xsl:apply-templates>

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 can use the select attribute to specify the order in which the child nodes are processed.

No comments:

Post a Comment