applications of xslt. generating word documents wordml provides formatting and content elements word...
TRANSCRIPT
Applications of XSLT
generating Word documents
• WordML provides formatting and content elements
• Word 2003 can read WordML files
• XSLT can be used to transform XML data file into a WordML file
<xsl:stylesheet version="1.0”
xmlns:xsl="http://www.w3.org/1999/XSL/Transform”
xmlns:o="urn:schemas-microsoft-com:office:office”
xmlns:w="http://schemas.microsoft.com/office/word/2003/2/wordml">
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">
progid="Word.Document”>
</xsl:processing-instruction>
<w:wordDocument>
<xsl:apply-templates/>
</w:wordDocument> </xsl:template>
XSLT , MSoffice and wordML namespaces
root template sets up a WordML document
<xsl:template match="chapter">
<o:DocumentProperties>
<o:Title>
<xsl:value-of select="@title"/>
</o:Title>
</o:DocumentProperties> <w:styles>
<w:style w:type="paragraph" w:styleId="Heading3">
<w:name w:val="heading 3"/> <w:pPr>
<w:pStyle w:val="Heading3"/>
</w:style> </w:styles>
<xsl:value-of select="@title"/>
<xsl:apply-templates/>
</xsl:template>
XML source content, MSOffice, WordML and XSLT elements all included in the template for chapter elements
XSLT selects the “title” attribute
MSOffice element defining document properties
WordML elements defining a paragraph style
<xsl:template match="link">
<w:hlink w:dest="{@url}">
<w:r> <w:rPr>
<w:rStyle w:val="Hyperlink"/>
<w:i/> </w:rPr>
<xsl:apply-templates/>
</w:r> </w:hlink>
</xsl:template>
</xsl:stylesheet>
XSLT template for “link” elements
apply templates for source content
end of stylesheet
XSLT and SVG
• SVG - Scalable Vector Graphics XML
• data sources can be rendered in SVG for visualisation
• example: the data source
<data> <datum>23</datum> <datum>94</datum> <datum>55</datum></data>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<svg xmlns:svg="http://www.w3.org/2000/svg"
viewBox="0 0 {10*(count(data/datum)+1)} 100">
<xsl:for-each select="data/datum">
<rect x="{10*position()}" y="{100- .}”
width="10" height="{.}”
fill="red" stroke="black"/>
</xsl:for-each>
</svg> </xsl:template> </xsl:stylesheet>
Result
ChessGML is an XML vocabulary to encode chess games.
Used by chess software but not easily readable otherwise.
And it is not understood by browsers
<game type="chess" variant="classic">... <moves ply-count="23"> <mp> <!-- 1. e4 e5 --> <m c="w"><p c="w" n="p"/><e2/><e4/></m> <m c="b"><p c="b" n="p"/><e7/><e5/></m> </mp>... Using XSLT it is possible to write a transform to animated SVG for display in browsers. The stylesheet first generates the initial chessboard. It also defines each chess piece as an SVG font glyph.
Then, for each move, SMIL Animation elements are generated.
Result
serving content to multiple devices
e.g. which image version, text-style features, etc...
e.g. use of particular WMLScript features
mobile phone, PDA, braille reader, web browser, ...
• Transform relational data to xml
• Statistically analyse xml data
• Generate an xml document based on business logic
• Render xml as HTML, WML, VXML
Guided Adaptive Search Frameworkhttp://www-128.ibm.com/developerworks/xml/library/x-levxslt/
Guided Adaptive Search Frameworkhttp://www-128.ibm.com/developerworks/xml/library/x-levxslt/
XI extracts data into an XML format
XSLT adapts output for different devices
XSLT transformations
XLink
• eXtensible Linking Language
• w3c-defined namespace
• XLink attributes can be attached to arbitrary XML elements
• they encode relationships and connections– simple hyperlinks– indices and tables of contents– text annotations– identify sub-networks
link types
• Defined by the xlink:type attribute
• simple
• extended
• locator
• arc
• title
• resource
Simple Links
• defines a one-way connection between two resources
• starting resource– the link element itself
• ending resource– identified by a URI
• defined by xlink:type and xlink:href attributes
<novel
xmlns:xlink=“http://www.w3.org/1999/xlink”
xlink:type = “simple”
xlink:href=“ftp://archive.org/pub/wizoz10.txt”>
<title>The wonderful Wizard of Oz</title>
<author>L. Frank Baum</author>
<year>1900</year>
</novel>
namespace can be defined in link element or any ancestor element
xlink:type attribute indicates the type of xlink, in this case simple
xlink:href is a URI for the xlink, in this case an ftp URL pointing at a plain text file.
Link behaviour
• under what circumstances is a link actuated?– “onclick” may be a meaningless concept– xlink:actuate attribute suggests when the link
should be actuated• onLoad
• onRequest
• other
• none
Link behaviour
• what should happen when a link is actuated?– xlink:show attribute suggests how an
application should react• new
• replace
• embed
• other
• none
Link semantics
• xlink may be used to represent many types of relationship
• parent - child
• previous - next
• employer - employee
• customer - supplier
• departure point - destination
• link semantics are text attributes that describe relationships
Link semantics
• xlink:title attribute– plain text– describes the ending resource
• xlink:role attribute– contains a URI– points to some sort of descriptive information
about the ending resource
Link semantics<novel
xlink:type = “simple”
xlink:href=“ftp://archive.org/pub/wizoz10. txt”
xlink:title = “The complete text of the novel”
xlink:role = “http://promo/net/pg/”>
<title>The wonderful Wizard of Oz</title>
<author>L. Frank Baum</author>
<year>1900</year>
</novel>
Extended links
• describes a collection of resources and a collection of paths between resources
• each path connects exactly two resources
• any resource may be connected to any other resource, including itself
• the extended link is a directed labelled graph made up of locators, arcs, resources and titles
Extended links
locator links
• indicates a remote resource
• xlink:type = “locator”• located with href attribute, which is a URI
• labelled with a label attribute, which names the element of which it is an attribute
• can also have title and role attributes
<novel
xlink:type = “extended”>
<title>The wonderful Wizard of Oz</title>
<author>L. Frank Baum</author>
<year>1900</year>
<edition xlink:type=“locator”
xlink:href=“urn:isbn:0688069444”
xlink:label=“ISBN0688069444”>
<edition xlink:type=“locator”
xlink:href=“urn:isbn:0192839306”
xlink:label=“ISBN0192839306”>
</novel>
extended link
locator link
locator link
arc links
• arcs represent paths between resources
• xlink:type = “arc”• xlink:from attribute identifies the source of
the linl
• xlink:to attribute identifies the target of the link
• from and to take locator labels as values
<series xlink:type = “extended”>
<novel xlink:type=“locator” xlink:label=“oz1”
xlink:href=“ftp://archive.org/pub/wizoz10.txt”>
<title>The wonderful Wizard of Oz</title>
<year>1900</year>
</novel>
<novel xlink:type=“locator” xlink:label=“oz2”
xlink:href=“ftp://archive.org/pub/ozland10.txt”>
<title>The Marvelous Land of Oz</title>
<year>1904</year>
</novel>
<novel xlink:type=“locator” xlink:label=“oz3”
xlink:href=“ftp://archive.org/pub/ozmoz10.txt”>
<title>Ozma of Oz</title>
<year>1907</year>
</novel>
<next xlink:type=“arc” xlink:from=“oz1” xlink:to=“oz2”/>
<next xlink:type=“arc” xlink:from=“oz2” xlink:to=“oz3”/>
<prev xlink:type=“arc” xlink:from=“oz2” xlink:to=“oz1”/>
<prev xlink:type=“arc” xlink:from=“oz3” xlink:to=“oz2”/>
</series>
The
Wizard
Of
Oz
Ozma
Of
Oz
The
Marvellous Land
Of
Oz
next next
prevprev
extended link example
internal and external resources
resource links
• represent elements within the document containing the links
• xlink:type = “resource”• also has label, role and title attributes
• resources are internal, locators are external
• arcs can be between any combination of locators and resources
title links
• used to contain more information than simply a title attribute
• the content of the element “ought to be” read as the title
• Xlink standards are only sparsely implemented
Linkbases
• documents linking only remote resources or inbound links are called linkbases
linkbase
XSLT and XLink• XSLT could be used to transform a linkbase
into a structural representation (in SVG say)
• templates could be defined to detect xlink attributes:
<xsl:template match=“*[@xlink:type=‘extended’]”>
<svg> <!--fancy network diagram --> </svg>
</xsl:template>
Xlink and DTDs
• xlink attributes must be defined in DTDs for documents to be valid
<!ATTLIST novel
xmlns:xlink CDATA #FIXED “http://www.w3.org/1999/Xlink”
xlink:type CDATA #FIXED ‘simple’
xlink:href CDATA #REQUIRED>