<?xml version="1.0"?>
<!DOCTYPE TEI.2 SYSTEM "teixlite.dtd"
[ 
 <!ATTLIST xref url CDATA #IMPLIED>
 <!ATTLIST xptr url CDATA #IMPLIED>
 <!ATTLIST figure file CDATA #IMPLIED>
 <!ATTLIST table tex CDATA #IMPLIED>
 <!ATTLIST figure width CDATA #IMPLIED>
 <!ATTLIST figure height CDATA #IMPLIED>
 <!ENTITY mdash "&#8212;">
 <!ENTITY pound "&#163;">
 <!ENTITY ldots "&#8230;">
]> 
<TEI.2>
  <teiHeader>
    <fileDesc>
      <titleStmt>
        <title>XSLT, continued </title>
      </titleStmt>
      <publicationStmt>
        <p> </p>
      </publicationStmt>
      <sourceDesc>
        <p></p>
      </sourceDesc>
    </fileDesc>
    <revisionDesc>
      <list>
        <item><date>July 2001</date> revised</item>
        <item><date>March 4th 2001</date> started</item>
      </list>
    </revisionDesc>
  </teiHeader>
  <text>
<front>
<titlePage>
<docTitle>
 <titlePart type="main">XSLT, continued</titlePart>
</docTitle>
<docAuthor>Sebastian Rahtz</docAuthor>
<docDate>July 2001</docDate>
</titlePage>
</front>
<body>
<div rend="slide">
<head>Recap 1</head>
<p>We have met the following XSL basic controls:
<eg><![CDATA[<xsl:stylesheet>
<xsl:template match="...">
<xsl:apply-templates select="...">
<xsl:value-of select="...">
<xsl:text>
<xsl:if test="...">
<xsl:choose>
<xsl:for-each select="...">
]]></eg></p>
</div>

<div rend="slide">
<head>Recap 2</head>
<p>... with the following `extras'
<eg><![CDATA[<xsl:sort>
<xsl:number>
id()
count() 
sum()
last()
]]></eg></p>
</div>

<div rend="slide">
<head>Other important commands</head>
<p><code><![CDATA[<xsl:element>]]></code>: make a new element </p>
<p><code><![CDATA[<xsl:attribute>]]></code>: add an attribute and value </p>
<p><code><![CDATA[<xsl:comment>]]></code>: make a comment</p>
<p><code><![CDATA[<xsl:processing-instruction>]]></code>: make a processing instruction </p>
<p><code><![CDATA[<xsl:copy>]]></code>: copy the current element</p>
<p><code><![CDATA[<xsl:copy-of>]]></code>: copy a (sub)tree </p>
<p><code><![CDATA[<xsl:message>]]></code>: put out a message</p>
<p><code><![CDATA[<xsl:key>]]></code>: construct a lookup table </p>

</div>

<div rend="slide">
<head>More functions</head>
<list>
<item><code>document</code>: (<emph>string</emph>)</item>
<item><code>generate-id</code>: (<emph>string</emph>)</item>
<item><code>position</code>: ()</item>
<item><code>name</code>: (<emph>node</emph>)</item>
<item><code>concat</code>: (<emph>string</emph>, <emph>string</emph>)</item>
<item><code>contains</code>: (<emph>string</emph>, <emph>string</emph>)</item>
<item><code>substring-before</code>: (<emph>string</emph>, <emph>string</emph>)</item>
<item><code>substring-after</code>: (<emph>string</emph>, <emph>string</emph>)</item>
<item><code>string-length</code>: (<emph>string</emph>)</item>
<item><code>translate</code>: (<emph>node</emph>,<emph>string</emph>, <emph>string</emph>)</item>
<item><code>normalize-space</code>: (<emph>string</emph>)</item>
</list>
</div>

<div rend="slide">
<head>Example of element/attribute creation</head>
<p><eg><![CDATA[
 <xsl:template match="hi">
   <xsl:comment>this was a hi element</xsl:comment>
   <xsl:message>doing a hi now </xsl:message>
   <xsl:element name="span">
     <xsl:attribute name="class">
       <xsl:value-of select="@rend"/>
     </xsl:attribute>
   </xsl:element>
 </xsl:template>
]]></eg>
(test1.xsl)
</p>
</div>

<div rend="slide">
<head>Copying input to output</head>
<p>Contrast
<eg><![CDATA[
 <xsl:template match="*">
   <xsl:copy><xsl:apply-templates/></xsl:copy>
 </xsl:template>
]]></eg>
with
<eg><![CDATA[
 <xsl:template match="*">
   <xsl:copy-of select="."/>
 </xsl:template>
]]></eg>
(test2.xsl, test3.xsl)
</p>
</div>

<div rend="slide">
<head>A useful catchall template</head>
<p><eg><![CDATA[<xsl:template match="p">
    <p><xsl:apply-templates/></p>
  </xsl:template>

  <xsl:template match="*">
   <span style="color: red">
     <xsl:text>&lt;</xsl:text>
     <xsl:value-of select="name(.)"/>
     <xsl:text>&gt;</xsl:text>
   </span>
   <xsl:apply-templates/>
   <span style="color: red">
     <xsl:text>&lt;/</xsl:text>
     <xsl:value-of select="name(.)"/>
     <xsl:text>&gt;</xsl:text>
   </span>
  </xsl:template>]]></eg>
(test4.xsl)
</p>
</div>

<div rend="slide">
<head> .. but what about attributes?</head>
<p><eg><![CDATA[<xsl:template match="*">
   <span style="color: red">
     <xsl:text>&lt;</xsl:text>
     <xsl:value-of select="name(.)"/>
     <xsl:for-each select="attribute::*">
       <xsl:text> </xsl:text>
       <xsl:value-of select="name(.)"/>
       <xsl:text>='</xsl:text><xsl:value-of select="."/>
       <xsl:text>'</xsl:text>
     </xsl:for-each>
     <xsl:text>&gt;</xsl:text>
   </span>
....]]></eg>
(test5.xsl)
</p>
</div>


<div rend="slide">
<head>String functions</head>
<p><eg><![CDATA[
  <xsl:template match="hi[@rend='upper']">
    <xsl:value-of select="translate(.,'abcdefghijklmnopqrstuvwxzy',
                          'ABCDEFGHIJKLMNOPQRSTUVWXZY')"/>
  </xsl:template>

  <xsl:template match="xref">
    <span style="color:red">
       (<xsl:value-of select="substring-before(@url,'://')"/> protocol) 
    </span> 
    <span style="color:green">
       <xsl:value-of select="substring-after(@url,'://')"/>
    </span>
  </xsl:template>
]]></eg>
(test6.xsl)
</p>
</div>


<div rend="slide">
<head>Using <code>generate-id()</code>: </head>
<p><eg><![CDATA[<xsl:template match="/">
    <p> <xsl:for-each select=".//p">
      <a href="#para-{generate-id()}">para 
        <xsl:number level="any"/>, </a>
      </xsl:for-each>
    </p>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="p">
    <p> <a name="para-{generate-id()}"/><xsl:apply-templates/></p>
  </xsl:template>]]></eg>
(test7.xsl)
</p>
</div>

<div rend="slide">
<head>Using keys</head>
<p><eg><![CDATA[<xsl:key name="elements" match="*" use="name(.)"/>

  <xsl:template match="/">
    <xsl:for-each select="key('elements','hi')">
      <xsl:sort select="."/>
      <xsl:value-of select="."/>: 
    </xsl:for-each>
  </xsl:template>
]]></eg>
(test8.xsl)
</p>
</div>

<div rend="slide">
<head>The <code>document</code> function</head>
<p>Using <code>document</code> to pull in another file and process it:
<eg><![CDATA[
<xsl:template match="*">
    <xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

<xsl:template match="xptr[@type='include']">
  <xsl:for-each select="document(@url)/*">
    <xsl:copy><xsl:apply-templates/></xsl:copy>
  </xsl:for-each>
</xsl:template>]]></eg>
(test13.xsl)
</p>
</div>

<div rend="slide">
<head>Named templates, parameters and variables</head>
<p><code><![CDATA[<xsl:template name="...">]]></code>: define a named template</p>
<p><code><![CDATA[<xsl:call-template>]]></code>: call a named template</p>
<p><code><![CDATA[<xsl:param>]]></code>: specify a parameter in a template definition</p>
<p><code><![CDATA[<xsl:with-param>]]></code>: specify a parameter when calling a template</p>
<p><code><![CDATA[<xsl:variable name="...">]]></code>: define a variable</p>

</div>



<div rend="slide">
<head>Variables</head>
<p><eg><![CDATA[<xsl:template match="p">
    <xsl:variable name="n">
      <xsl:number/>
    </xsl:variable>
    Paragraph <xsl:value-of select="$n"/>
    <a name="P{$n}"/>
       <xsl:apply-templates/>
  </xsl:template>]]></eg>
(test11.xsl)
</p>

</div>


<div rend="slide">
<head>Named templates</head>
<p><eg><![CDATA[  <xsl:template match="/div">
    <html>
     <xsl:call-template name="header">
      <xsl:with-param name="title" select="head"/>
     </xsl:call-template>
     <xsl:apply-templates/>
   </html>
  </xsl:template>

  <xsl:template name="header">
    <xsl:param name="title"/>
    <head>
      <title><xsl:value-of select="$title"/></title>
    </head>
  </xsl:template>]]></eg>
(test12.xsl)
</p>

</div>


<div rend="slide">
<head>Top-level commands</head>
<p><code><![CDATA[<xsl:import href="...">]]></code>: include a file of XSLT templates, overriding them as needed</p>
<p><code><![CDATA[<xsl:include href="...">]]></code>: include a file of XSLT templates, but do not override them</p>
<p><code><![CDATA[<xsl:output>]]></code>: specify output characteristics of this job</p>

</div>



<div rend="slide">
<head>Some useful <code>xsl:output</code> attributes</head>
<p><code>method="</code>xml | html | text"</p>
<p><code>encoding="</code><emph>string"</emph></p>
<p><code>omit-xml-declation="</code>yes | no"</p>
<p><code>doctype-public="</code><emph>string"</emph></p>
<p><code>doctype-system="</code><emph>string"</emph></p>
<p><code>indent="</code>yes | no"</p>
</div>



<div rend="slide">
<head>An identity transform</head>
<p><eg><![CDATA[<xsl:output method="xml" indent="yes" encoding="iso-8859-1"
    doctype-system="teixlite.dtd"/>
 
 <xsl:template match="/">
    <xsl:copy-of select="."/>
 </xsl:template>
]]></eg>
(test9.xsl)
</p>
</div>

<div rend="slide">
<head>A near-identity transform</head>
<p><eg><![CDATA[<xsl:template match="*|@*|processing-instruction()">
 <xsl:copy>
 <xsl:apply-templates 
    select="*|@*|processing-instruction()|comment()|text()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="text()">
    <xsl:value-of select="."/> 
</xsl:template>

<xsl:template match="p">
  <para><xsl:apply-templates/></para> 
</xsl:template>]]></eg>
(test10.xsl)
</p>
</div>

<div rend="slide">
<head>Generating plain text</head>
<p><eg><![CDATA[<xsl:output method="text"/>
<xsl:template match="text()">
    <xsl:call-template name="split">
      <xsl:with-param name="text" 
        select="concat(normalize-space(.),' ')"/>
    </xsl:call-template>
</xsl:template>

<xsl:template name="split">
    <xsl:param name="text"/>
    <xsl:if test="not($text='')">
      <xsl:value-of select="substring-before($text,' ')"/><xsl:text>
</xsl:text>
      <xsl:call-template name="split">
        <xsl:with-param name="text" select="substring-after($text,' ')"/>
      </xsl:call-template>
    </xsl:if>
</xsl:template>]]></eg>
(test14.xsl)
</p>
</div>

<div rend="slide">
<head>XSLT extensions</head>
<p>Although we will not be covering them here, most XSLT processors
support various extensions, which will probably be formalized in version 2.0:
<list>
<item>The ability to create <emph>multiple</emph> output files from
one input</item> <item>The ability to `escape' to another language (eg
Java) for special purposes</item> 
<item>The ability to turn results into input trees for further processing</item>
</list>
	</p>
</div>


<div rend="slide">
<head>TEI Stylesheets</head> 
<p>A library of stylesheets for
transforming TEI documents to either HTML or XSL Formatting Objects,
at <xptr url="http://www.hcu.ox.ac.uk/Stylesheets"/>, with a
form-filling interface for the HTML at <xptr
url="http://www.hcu.ox.ac.uk/cgi-bin/tei/stylebear"/>
</p>
</div>

<div rend="slide">
<head>TEI Stylesheets (example)</head> 
<p>An example of an importing stylesheet:
<eg><![CDATA[<xsl:stylesheet 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">
<xsl:import 
 href="http://www.hcu.ox.ac.uk/TEI/Stylesheets/teihtml.xsl"/>
<xsl:variable name="splitLevel">1</xsl:variable>
<xsl:variable name="numberHeadings"></xsl:variable>
<xsl:variable name="topNavigationPanel">true</xsl:variable>
<xsl:variable name="bottomNavigationPanel">true</xsl:variable>
</xsl:stylesheet>
]]></eg>
</p>
</div>

<!--
<div rend="slide">
<head>XML publishing possibilities</head> 
<p><list>
<item>Generate HTML for direct web display</item>
<item>Store the XML in a database and use XSLT to format the results</item>
<item>Generate an HTML file, and read it into Word; you can then
print to PDF, or save as RTF for import into a DTP program</item>
<item>Convert to XSL Formatting Objects, and process to PDF</item>
<item>Generate plain text and put into a database</item>
</list>
</p>
</div>
-->

</body>
</text>
</TEI.2>


