Upload
bijoy-kureekkal
View
1.734
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
A peek into the world of
XSLT• Author
• Neenu George
“Style is what gives value and currency to thoughts.”
Arthur Schopenhauer (1788-1860) German philosopher.
“Style is a simple way of saying complicated things”
Jean Cocteau (1889-1963) French author and filmmaker.
“The proper words in the proper places are the true definition of style.”
Jonathan Swift (1667-1745) Irish-born English satirist.
AGENDA
• What is XSLT ?• Programming with XSLT • Example• Use of XSLT in Polaris Application• Conclusion• Q&A
About XSLT
What is XSLT?XSL stands for EXtensible Stylesheet LanguageLanguage for transforming XML documentsA programming language for XML documentsA functional language, based on value substitutionAugmented with pattern matchingAnd also template substitution to construct output (based on namespacesUses XML syntax
XSLT in Motion
• Portals / web sites
• Standardization
• Games
• Document Management
• Enterprise Integrations
• RSS, SVG, UBL, LegalXML, HrXML, XBRL
• And its Everywhere ……………
Why transform?
• Convert one schema to another– I say potato, you say paragraph
• Rearrange data for formatting
Programming with XSLT
Correct Style Sheet Declaration
The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>
W3C XSLT Recommendation is:
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="myTemplateName"> ...body of template... </xsl:template>
set of rules that are called templatesA template contains rules to apply when a specified node is matched.Acts as functions in java<xsl:call-template name="myTemplateName"/>
XSLT <xsl:template> Element
used to extract the value of a selected node.<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:value-of select="XPath expression"/>selects the contents of an element and adds it to the output stream
XSLT <xsl:value-of> Element
element allows you to do looping in XSLT
<xsl:for-each> element can be used to select every XML element of a specified node-set<xsl:for-each select="XPath expression">
XSLT <xsl:foreach> Elements
XSLT <xsl:sort> Element
<xsl:sort> element is used to sort the output.To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file:
xsl:sort select="author"/>
XSLT <xsl:if> Element<xsl:if> element is used to put a conditional test against the content of the XML file
test against the content of the XML file, add an <xsl:if> element to the XSL document.
<xsl:if test="expression"> <!-- Content: template --></xsl:if>
XSLT <xsl:choose> Element
The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests.
<xsl:choose> <xsl:when test="expression"> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise></xsl:choose>
XPath and its use in XSLT
• An expression language over XML trees• Used to identify sets of elements
– “all paragraphs”– “all paragraphs directly inside footnotes”– “the section with ID=“sec37”– “footnotes with author=‘Knuth’”– “first paragraph in each section”– “the parent of each caption”
• Then you can say what to do with them…
What’s inside an XSLT transform?
• Any number of “templates”• A template uses Xpath to match nodes• Highest priority matching template selected• Then the remplate takes over and
generates:– Literal output XML (based on
namespace)– Computational results (of XSLT functions)– Results of further template applications– Results of queries on the document
• Many options
Code Examples
Conclusion
Strategies for XSLT
Try to pick a single style as much as possible
May vary by project
Mixing may be necessary but can get confusing
Be sure you understand (and probably override the default rules)
Shorter patterns are better
<xsl:value-of> and <xsl:if> may be easier to deal with than a complex path
References
Key siteshttp://www.w3.org/Style/XSL http://www.mulberrytech.com/xsl/xsl-list http://www.oasis-open.org/cover/xsl.html
Interactive XSLT reference http://www.zvon.org/xxl/XSLTreference/Output/
XSLT: 2nd Edition Programmer’s Reference Michael Kay [Good reference; clear, but not really a tutorial]
XSLT & XPath On the EdgeTennison [And her other books]