applications of xslt. generating word documents wordml provides formatting and content elements word...

37
Applications of XSLT

Upload: joshua-powell

Post on 28-Mar-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

Applications of XSLT

Page 2: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 3: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

<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

Page 4: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

<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

Page 5: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

<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

Page 6: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform
Page 7: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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>

Page 8: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 9: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

Result

Page 10: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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.

Page 11: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

Result

Page 12: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 13: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

• 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/

Page 14: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 15: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 16: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

link types

• Defined by the xlink:type attribute

• simple

• extended

• locator

• arc

• title

• resource

Page 17: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 18: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 19: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 20: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

Link behaviour

• what should happen when a link is actuated?– xlink:show attribute suggests how an

application should react• new

• replace

• embed

• other

• none

Page 21: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 22: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 23: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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>

Page 24: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 25: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

Extended links

Page 26: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 27: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

<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

Page 28: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 29: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 30: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 31: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

The

Wizard

Of

Oz

Ozma

Of

Oz

The

Marvellous Land

Of

Oz

next next

prevprev

extended link example

Page 32: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

internal and external resources

Page 33: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 34: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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

Page 35: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

Linkbases

• documents linking only remote resources or inbound links are called linkbases

linkbase

Page 36: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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>

Page 37: Applications of XSLT. generating Word documents WordML provides formatting and content elements Word 2003 can read WordML files XSLT can be used to transform

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>