<?xml version="1.0" ?> <html xmlns="http://www.w3.org/HTML/1998/html4" xmlns:nms="http://www.names.net/address"> <head><title>Addresses</title></head> <body> <nms:addresses nms:version="1.0"> <hr/> <nms:person> <nms:title>Mr.</nms:title> <nms:first>Simon</nms:first> <nms:last>Schuster</nms:last> </nms:person> <hr/> <!-- ... --> </body> </html>
<?xml version="1.0" ?> <html xmlns="http://completely-silly-address/ha/ha" xmlns:nms="brrr://another-silly-address/snicker"> ...
<?xml version="1.0" ?> <html xmlns="http://www.w3.org/HTML/1998/html4" xmlns:nms="http://www.names.net/address"> <heard><tutle>Addresses</tutle></heard> <bodi> <nms:addresses nms:version="1.0"> <gr/> ....
<?xml version="1.0"?> <purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country="US"> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Old Town</city> <state>PA</state> <zip>95819</zip> </billTo> <comment>Hurry, my lawn is going wild!</comment> <items> <item partNum="872-AA"> <productName>Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum="926-AA"> <productName>Baby Monitor</productName> <quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </item> </items> </purchaseOrder>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:annotation> <xsd:documentation xml:lang="en"> Purchase order schema for Example.com. Copyright 2000 Example.com. All rights reserved. </xsd:documentation> </xsd:annotation> <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> <xsd:element name="comment" type="xsd:string"/> <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name="billTo" type="USAddress"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="items" type="Items"/> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"/> </xsd:complexType> <xsd:complexType name="USAddress"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="street" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="zip" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/> </xsd:complexType> <xsd:complexType name="Items"> <xsd:sequence> <xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="productName" type="xsd:string"/> <xsd:element name="quantity"> <xsd:simpleType> <xsd:restriction base="xsd:positiveInteger"> <xsd:maxExclusive value="100"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="USPrice" type="xsd:decimal"/> <xsd:element ref="comment" minOccurs="0"/> <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/> </xsd:sequence> <xsd:attribute name="partNum" type="SKU" use="required"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- Stock Keeping Unit, a code for identifying products --> <xsd:simpleType name="SKU"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\d{3}-[A-Z]{2}"/> </xsd:restriction> </xsd:simpleType> </xsd:schema>
axis-name :: node-test [predicate]*For example:
child::para[attribute::type="warning"]
<template match="para"> <apply-templates/> </template>
<template match="text()"> <value-of select="."/> </template>
<template match="*"> <apply-templates/> </template>
<template match="hide"/>
<template match="chapter"> <apply-templates select="title"/> <apply-templates select="para"/> </template>
<template match="chapter"> <apply-templates select="title"/> <apply-templates/> </template>
<template match="chapter"> This text will appear before the content of chapter <apply-templates/> This text will appear after the content of chapter </template>
<template match="chapter"> <text> "</text><apply-templates/><text>" </text> </template>
<template match="book"> <element name="HTML"> <element name="HEAD"> <element name="TITLE">The Title</element> </element> <element name="BODY"> <apply-templates/> </element> </element> </template>
<xsl:template match="book"> <HTML> <HEAD><TITLE>The Title</TITLE></HEAD> <BODY> <xsl:apply-templates/> </BODY> <HTML> </xsl:template>
<para>Hello <hi>world</hi>!</para>
<xsl:template match="para"> <xsl:copy-of select="."> </xsl:template>Output: Hello <hi>world</hi>!
<xsl:template match="para"> <xsl:value-of select="."> </xsl:template>Output: Hello world!
<xsl:template match="para"> <xsl:value-of select="hi"/> </xsl:template>Output: world
Input: <para type="important">Hello world!</para> Template: <xsl:template match="para"> <P> [TYPE: <xsl:value-of select="@type"/>] <xsl:apply-templates/> </P> </xsl:template> Output: <p>[TYPE: important] Hello world!</p>
Input: <first>John</first> <last>Smith</last> <first>Frank</first> <last>Furter</last> Intended output: <p>John Smith</p> <p>Frank Furter</p>
<xsl:template match="first"> <P> <xsl:value-of select="."/> <!-- WRONG! --> </xsl:template> <xsl:template match="last"> <xsl:value-of select="."/> </P> <!-- WRONG! --> </xsl:template>
<xsl:template match="first"> <p> <xsl:value-of select="."/> <!-- Escape <p> --> </xsl:template> <xsl:template match="last"> <xsl:value-of select="."/> </p> <!-- Escape </p> --> </xsl:template>However, this doesn't work:
<p> John Smith </p> <p> Frank Furter </p>
<xsl:template match="first"> <xsl:text disable-output-escaping="yes"><p></xsl:text> <xsl:value-of select="."/> </xsl:template> <xsl:template match="last"> <xsl:value-of select="."/> <xsl:text disable-output-escaping="yes"></p></xsl:text> </xsl:template>
... <xsl:apply-templates select="first"/> ... <xsl:template match="first"> <P> <xsl:apply-templates/> <xsl:apply-templates select="following-sibling::last[1]"/> </P> </xsl:template>
<xsl:stylesheet> ... </xsl:stylesheet>
<xsl:transform> ... </xsl:transform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> . . . </xsl:stylesheet>
saxon esslli02.xml tlslides.xsl > esslli02.html
<!DOCTYPE TEI.2 SYSTEM 'teixlite.dtd' [ <?xml-stylesheet type="text/xsl" href="tlslides.xsl"?> ]>
<?xml-stylesheet type="text/xsl" href="#localStyle"?> <!DOCTYPE TEI.2 SYSTEM 'teixlite.dtd'> <TEI.2> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="localStyle"> ... </xsl:stylesheet> </TEI.2>
<xsl:import href="tbl1.xsl"/> <!--first element, included at end--> <xsl:include href="tbl2.xsl"/> <!--included here-->
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" standalone="no" doctype-system="tei2.dtd" doctype-public="-//TEI P3//DTD Main Document Type//EN" indent="yes" cdata-section-elements="code eg" media-type="text/xml"/>
<xsl:preserve-space elements="head p"/> <xsl:strip-space elements="div"/>
<xsl:template match="div"> ... </xsl:template> <xsl:template match="head"> ... </xsl:template> <xsl:template match="p"> ... </xsl:template>
<xsl:template match="A//X"> ... </xsl:template> <xsl:template match="X[C]"> ... </xsl:template> <xsl:template match="P[S]/X"> ... </xsl:template>
<xsl:template match="X[@a]"> ... </xsl:template> <xsl:template match="X[@a='v']"> ... </xsl:template>
<xsl:template match="para//emph" priority="1"> ... </xsl:template> <xsl:template match="quote//emph" priority="2"> ... </xsl:template>
<xsl:template match="title"> <!-- formatting for <title> in the body of document --> </xsl:template> <xsl:template match="title" mode="toc"> <!-- formatting for <title> in the table of contents --> </xsl:template> ... <!-- Generating the table of contents: --> <xsl:apply-templates mode="toc" select="//title"/>
<image file="house.jpg" x="100" y="100">My house</image>Output:
<IMG SRC="house.jpg" HEIGHT="100" WIDTH="100" ALT="My house"/>
<xsl:template match="image"> <xsl:element name="IMG"> <xsl:attribute name="SRC"><value-of select="@name"/></xsl:attribute> <xsl:attribute name="HEIGHT"><value-of select="@x"/></xsl:attribute> <xsl:attribute name="WIDTH"><value-of select="@y"/></xsl:attribute> <xsl:attribute name="ALT"><value-of select="."/></xsl:attribute> </xsl:element> </xsl:template>
<xsl:template match="image"> <IMG SRC="{@name}" HEIGHT="{@y}" WIDTH="{@x}" ALT="{text()}"/> </xsl:template>
<xsl:if test="not(position() = last)"> <xsl:text>, </xsl:text> </xsl:if>
<xsl:choose> <xsl:when test="@type='error'"> <FONT color="red"><xsl:apply-templates/></FONT> </xsl:when> <xsl:when test="@type='warning'"> <FONT color="yellow"><xsl:apply-templates/></FONT> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose>
Input: <people> <name> <first>John</first> <last>Smith</last> <age>53</age> </name> <name> <first>Frank</first> <last>Furter</last> <age>35</age> </name> </people> Template: <xsl:template match="people"> <DIV> <xsl:apply-templates> <xsl:sort select="last" language="en" /> <xsl:sort select="age" data-type="number" order="descending"/> </xsl:apply-templates> </DIV> </xsl:template>
Input: Output: <people> <name>John Smith</name> 1) John Smith <name>Frank Furter</name> 2) Frank Furter </people> <xsl:template match="name"> <xsl:number/> <xsl:text>) </xsl:text> <xsl:apply-templates/> </xsl:template>
<xsl:number format="a"/>. <xsl:apply-templates/> Output: a. John Smith b. Frank Furter <xsl:number format="(i)"/> <xsl:apply-templates/> Output: (i) John Smith (ii) Frank Furter
<xsl:number value="position()" format="1) "/> Output: 1) John Smith 2) Frank Furter <xsl:number value="last() + 1 - position()" format="1) "/> Output: 2) John Smith 1) Frank Furter
<xsl:number count="item[not(status@='ignore'")]/>
<xsl:number count="normal | special"/>
<xsl:template match="title"> <H1> <xsl:number count="div1"/>) <xsl:apply-templates/> </H1> </template>
<xsl:number count="div1"/>. <xsl:number count="div2"/>) equivalently: <xsl:number level="multiple" count="div1 | div2" format="1.1)"/>
<xsl:template match="table/title"> <TITLE> <xsl:number level="any" count="table"/> <xsl:apply-templates/> </TITLE> </xsl:template>
<!ATTLIST div name ID #REQUIRED>
<xsl:template match="id('chp-intro')"> ... </xsl:template>
<xsl:template match="id('chp-intro chp-conc')"> ... </xsl:template>
<xsl:key name="Personnel" match="people/name" use="last"/>
<xsl:template match="key('Personnel' 'Smith')"> ... </xsl:template>
<xsl:variable name="color">red</xsl:variable> <xsl:variable name="colour" select="@color"/>
<xsl:variable name="n">1</xsl:variable> <xsl:variable name="n">2</xsl:variable> <!-- WRONG! -->
<xsl:stylesheet ...> <xsl:variable name="level">1</xsl:variable> <xsl:template match="*"> <xsl:variable name="level">2</xsl:variable> <!-- OK -->
The sky was <FONT color="{$color}"><xsl:value-of select="$color"></FONT>
<xsl:variable name="warning"><hi>Warning!</hi></xsl:variable> ... <xsl:copy-of select="$warning">
<xsl:template name="line"> <BR/><HR/><BR/> </xsl:template>
<xsl:template select="chapter"> <xsl:call-template name="line"> <H1>New chapter</H1> <xsl:apply-templates/> </xsl:template>
<xsl:template name="colorize"> <xsl:param name="color">white</xsl:param> <FONT color="{$color}"> <xsl:apply-templates/> </FONT> </xsl:template> <xsl:template select="error"> <xsl:call-template name="colorize"> <xsl:with-param name="color">red</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template select="warning"> <xsl:call-template name="colorize"> <xsl:with-param name="color">yellow</xsl:with-param> </xsl:call-template> </xsl:template>
<xsl:for-each select="row"> ... <xsl:for-each select="cell"> ... </xsl:for-each> </xsl:for-each>(can also use <sort>)
<xsl:template select="//warning/*/para"> <xsl:message>Template //warning/*/para is activated!</xsl:message> <xsl:apply-templates/> </xsl:template>
<BOOK xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ... <xsl:value-of .../> ... </BOOK>
<P>A <B>bold</B> statement.</P>
<block>A <wrapper font-weight="bold">bold</wrapper> statement.</block>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <template select="P"> <fo:block><apply-templates/></fo:block> </template> ...
<root> <layout-master-set> <simple-page-master master-name="front"> <!-- TEMPLATE 1 --> </simple-page-master> <simple-page-master master-name="body"> <!-- TEMPLATE 2 --> </simple-page-master> </layout-master-set> <page-sequence-master master-name="front"> <!-- CONTENT 1 --> </page-sequence-master> <page-sequence-master master-name="body"> <!-- CONTENT 2 --> </page-sequence-master> </root>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" > <fo:layout-master-set> <fo:simple-page-master master-name="only" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm"> <fo:region-body margin-top="3cm"/> <fo:region-before extent="3cm"/> <fo:region-after extent="1.5cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-name="only" initial-page-number="1"> <fo:static-content flow-name="xsl-region-before"> <fo:block text-align="end" font-size="10pt" font-family="serif" line-height="14pt"> XML Recommendation - p. <fo:page-number/> </fo:block> </fo:static-content> <fo:flow flow-name="xsl-region-body"> <fo:block font-size="18pt" font-family="sans-serif" line-height="24pt" space-after.optimum="15pt" background-color="blue" color="white" text-align="center" padding-top="0pt"> Extensible Markup Language (XML) 1.0 </fo:block> <fo:block font-size="16pt" font-family="sans-serif" line-height="20pt" space-before.optimum="10pt" space-after.optimum="10pt" text-align="start" padding-top="0pt"> Abstract </fo:block> <fo:block font-size="12pt" font-family="sans-serif" line-height="15pt" space-after.optimum="3pt" text-align="start"> The Extensible Markup Language (XML) is a subset of SGML that is completely described in this document. Its goal is to enable generic SGML to be served, received, and processed on the Web in the way that is now possible with HTML. XML has been designed for ease of implementation and for interoperability with both SGML and HTML. For further information go to <fo:basic-link external-destination="normal.pdf">normal.pdf</fo:basic-link> </fo:block> ...