<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="slides.xsl"?>
<slides name="presentation"    xmlns="http://www.hoise.com/vmp/manual/1.0">

<title>XSL an introduction</title>

<!--================================================================-->
<slide>
<title>XSLT - An introduction
 </title>
  <content>
<p>
<address-line>Ad Emmen</address-line>
<address-line>Genias Benelux</address-line>
<address-line>James Stewartstraat 24</address-line>
<address-line>NL-1325 JN Almere</address-line>
<address-line>The Netherlands</address-line>
<address-line>emmen@genias.nl</address-line> 
<address-line> http://www.genias.nl/</address-line>
</p>
<p>May  2002, 
Almere
</p>
  </content>
</slide>

<!--================================================================-->


<slide>
 <title>
Why XSLT
 </title>
  <content>
    <ul>
      <li>XML separates contents from formatting</li>
      <li>An XML-tag like &lt;b&gt; does not  mean anything by itself</li>
      <li>For instance Bold, Big, Brown, Bubble</li>
      <li>You need a formatting instruction to tell how it should be formatted</li>
      <li>That is where stylesheets come in</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 XML Stylesheet languages: CSS and XSL
 </title>
  <content>
    <ul>
      <li>Cascading Style Sheets (CSS)</li>
       <ul> 
         <li>Same as for HTML</li>
         <li>Tell how each element should be displayed</li>
         <li>Useful for computer displays</li>   
      </ul>   
     <li>Extensible Stylesheet Language (XSL)</li>
     <ul> 
       <li>More powerful</li> 
       <li>Also for printing and other display units</li>
       <li>Detailed control over lay-out</li>
       <li>Elements can be rearranged - transformed - before display</li>
    </ul>
   </ul>
  </content>
</slide>
<!--================================================================-->




<slide>
 <title>
    XSL, XSLT and XSL-FO  
 </title>
  <content>
    <ul>
      <li>XSL consists of two separate languages plus a supporting standard </li>
      <li>XSLT- transformation language</li>
      <li>XSL-FO - formatting language</li>
      <li>You also need XPath: way of addressing elements</li>
      <li>XSLT can be used without XSL-FO: powerful in itself</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 What is XSLT 
 </title>
  <content>
    <ul>
      <li>With XSLT you can transform one or more XML documents into a new one</li>
      <li>Transformation process guided by an XSLT-Stylesheet</li>
      <li>What is so special about that?</li>
      <li>Well, remember also XHTML and WML are XML-documents</li>
      <li>With XSLT you can create web sites and WAP sites</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->


<slide>
 <title>
 And that is not all..
 </title>
  <content>
    <ul>
      <li>Another important aspect of XML is its use for data-exchange and access</li>
      <li>Merging machine data from site A with rankings from site B</li>
      <li>Exchanging information through messages (SOAP)</li>
      <li>Use XSLT to access the data and "web services" and produce a new XML document</li>
      <li>The original data has to be available in XML</li>
      <li>.. or a format that can be converted to XML like "raw" HTML with Tidy</li> 
    </ul>

  </content>
</slide>



<!--================================================================-->




<slide>
 <title>
  An XML document
 </title>
  <content>
<vmp:example>
<pre>
&lt;?xml version="1.0" ?&gt;
&lt;ors:list-of-systems  
     xmlns:ors="http://www.hoise.com/ors/0.1"
     xmlns:vmp="http://www.hoise.com/vmp/manual/0.1" 
     id="gone"&gt;


&lt;ors:system&gt;
 &lt;ors:name&gt;Alex AVX 2&lt;/ors:name&gt;
 &lt;ors:year-of-introduction&gt;1992&lt;/ors:year-of-introduction&gt;  
 &lt;ors:year-of-exit&gt;1997&lt;/ors:year-of-exit&gt;
 &lt;ors:machine-type&gt;&lt;ors:general&gt;RISC-based distributed-memory multi-processor.&lt;/ors:general&gt;&lt;/ors:machine-type&gt;
 &lt;ors:peak-performance unit="gflops"&gt;3.84&lt;/ors:peak-performance&gt;
 &lt;ors:remarks&gt;System is obsolete, there is no new system planned. &lt;/ors:remarks&gt;
&lt;/ors:system&gt;


&lt;ors:system&gt;
 &lt;ors:name&gt;Alliant FX/2800&lt;/ors:name&gt;
 &lt;ors:year-of-introduction&gt;1989&lt;/ors:year-of-introduction&gt;  
 &lt;ors:year-of-exit&gt;1992&lt;/ors:year-of-exit&gt;
 &lt;ors:machine-type&gt;&lt;ors:general&gt;Shared-memory vector-parallel, max. 28 processors.&lt;/ors:general&gt;&lt;/ors:machine-type&gt;
 &lt;ors:peak-performance unit="mflops"&gt;1120&lt;/ors:peak-performance&gt;
 &lt;ors:remarks&gt;Manufacturer out of business.
 &lt;/ors:remarks&gt;
&lt;/ors:system&gt;


&lt;ors:system&gt;
 &lt;ors:name&gt;AxilSCC&lt;/ors:name&gt;
 &lt;ors:year-of-introduction&gt;1996&lt;/ors:year-of-introduction&gt;  
 &lt;ors:year-of-exit&gt;1997&lt;/ors:year-of-exit&gt;
 &lt;ors:machine-type&gt;&lt;ors:general&gt;RISC-based distributed-memory system, max. 512 processors.&lt;/ors:general&gt;&lt;/ors:machine-type&gt;
 &lt;ors:peak-performance unit="gflops"&gt;76.8&lt;/ors:peak-performance&gt;
 &lt;ors:remarks&gt;System is not marketed anymore by Axil.
 &lt;/ors:remarks&gt;
&lt;/ors:system&gt;


&lt;ors:system&gt;
 &lt;ors:name&gt;BBN TC2000&lt;/ors:name&gt;
 &lt;ors:year-of-introduction&gt;---&lt;/ors:year-of-introduction&gt;  
 &lt;ors:year-of-exit&gt;1990&lt;/ors:year-of-exit&gt;
 &lt;ors:machine-type&gt;&lt;ors:general&gt; Virtual shared-memory parallel, max. 512 processors.&lt;/ors:general&gt;&lt;/ors:machine-type&gt;
 &lt;ors:peak-performance unit="gflops"&gt;1&lt;/ors:peak-performance&gt;
 &lt;ors:remarks&gt;Manufacturer has discontinued marketing parallel computer systems.
 &lt;/ors:remarks&gt;
&lt;/ors:system&gt;

&lt;/ors:list-of-systems&gt;
</pre>
</vmp:example> 
  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 A basic XSLT Stylesheet copying the input document to the output
 </title>
  <content>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsl:stylesheet 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0"&gt;


&lt;xsl:template match="/"&gt;
 &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="*|@*"&gt;
  &lt;xsl:copy&gt;
    &lt;xsl:apply-templates select="@*"/&gt;
    &lt;xsl:apply-templates select="node()"/&gt;
  &lt;/xsl:copy&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
    <ul>
      <li>Stylesheets are XML documents</li>
      <li>Document element: 'stylesheet' or 'transform'</li>
      <li>Important is the name-space binding url</li>
      <li>A stylesheet consists of templates and some other top level elements</li>
      <li>Optional: DTD </li> 
    </ul>

  </content>
</slide>
<!--================================================================-->




<slide>
 <title>
 Tree structure 
 </title>
  <content>
    <ul>
      <li>XML documents have a tree-like structure</li>
      <li>There is only one starting element: the root</li>
      <li>The root contains one document-element</li>
      <li>Attributes are considered "leaves" of the element to which they belong</li>
      <li>An XSLT processor takes an input tree and converts it to an output tree</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
  A basic XSLT Stylesheet doing something 
 </title>
  <content>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:template match="system"&gt;
    &lt;h3&gt;&lt;xsl:value-of select="name"/&gt;&lt;/h3&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
    <ul>
      <li>xsl:template works recursively for all "system"-elements</li>
      <li>In the output it will put the contents of the "name"-element, surrounded by HTML-type heading-3 tags</li>
      <li>Will not work with our example file:</li>
      <li>Include namespace "ors"</li>
      <li>Provide a starting element for the XSLT-processor</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
  Creating a complete HTML document
 </title>
  <content>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:ors="http://www.hoise.com/ors/0.1"&gt; 

&lt;xsl:template match="/"&gt;
  &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="ors:list-of-systems"&gt;
&lt;html&gt;
 &lt;head&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;xsl:apply-templates /&gt;
 &lt;/body&gt;
&lt;/html&gt;
&lt;/xsl:template&gt;

  &lt;xsl:template match="ors:system"&gt;
    &lt;h3&gt;&lt;xsl:value-of select="ors:name"/&gt;&lt;/h3&gt;
&lt;p&gt;&lt;b&gt;&lt;xsl:text&gt;Year-of-Introduction: &lt;/xsl:text&gt;&lt;/b&gt;&lt;xsl:value-of select="ors:year-of-introduction"/&gt;&lt;/p&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
    <ul>
      <li>The "ors"-namespace has been added</li>
      <li>The document-element "ors:list-of-systems" now results in a complete html file</li>
      <li>"xsl:text" is used to insert text - especially useful for leading and trailing spaces</li>
     </ul>

  </content>
</slide>
<!--================================================================-->




<slide>
 <title>
 Matching elements
 </title>
  <content>
    <ul>
      <li>Templates work when they find a match</li>
      <li>You match elements by their name</li>
      <li>Position is relative to the  postion of the current element</li>
      <li>"/" matches root</li>
      <li>"," matches contents of current element</li>
      <li>"name" matches children with name "name"</li>
       <li>"name/othername" matches children with name "othername" with parent "name"</li>
       <li>"name/*" matches all elements with parent "name"</li>
       <li> And more. In general: should be an XPath expression</li>
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
  Matching examples
 </title>
  <content> 


    <ul>
      <li>&lt;xsl:template match="ors:system"/&gt; matches "ors:system" </li>
      <li>&lt;xsl:template match="system"/&gt; matches "system" not "ors:system" </li>
      <li>&lt;xsl:template match="ors:machine-type/ors:general"/&gt; matches "ors:general" elements with parent "ors:machine-type" </li>
       <li>&lt;xsl:template match="ors:general"/&gt; matches "ors:general" elements </li>
     <li></li>
      <li></li>
      <li></li> 
    </ul>

  </content>
</slide>
<!--================================================================-->




<slide>
 <title>
 Narrowing selections 
 </title>
  <content>
    <ul>
      <li>name["." = "this"] selects only elements with name "name" and contents "this"]</li>
       <li>system[year-of-exit &gt; "1992"] selects the element 'system' whith a child-elem=ent year-of-exit' with content '1992'</li>
      <li></li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
Example  
 </title>
  <content>
<pre>

&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:ors="http://www.hoise.com/ors/0.1"&gt; 

&lt;xsl:template match="/"&gt;
  &lt;xsl:apply-templates /&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="ors:list-of-systems"&gt;
&lt;html&gt;
 &lt;head&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;xsl:apply-templates /&gt;
 &lt;/body&gt;
&lt;/html&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="ors:system"&gt;
 &lt;h3&gt;&lt;xsl:value-of select="ors:name"/&gt;&lt;/h3&gt;
 &lt;p&gt;&lt;b&gt;&lt;xsl:text&gt;Year-of-Introduction: &lt;/xsl:text&gt;&lt;/b&gt;
 &lt;xsl:apply-templates select="ors:year-of-introduction"/&gt;&lt;/p&gt;
&lt;/xsl:template&gt;


&lt;xsl:template match="ors:year-of-introduction[ . &gt;= '1992']"&gt;  
 &lt;font color="red"&gt;&lt;xsl:value-of select="."/&gt;&lt;/font&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match="ors:year-of-introduction"&gt;  
 &lt;xsl:value-of select="."/&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;

</pre>

    <ul>
      <li>When more templates match, the most specific gets executed</li>
      </ul>

  </content>
</slide>
<!--================================================================-->


<!--================================================================-->



<slide>
 <title>
Matching attributes  
 </title>
  <content>
    <ul>
      <li>match with @attribute</li>
      <li>name/@attribute matches the attribute of elements with name"name"</li>
      <li>name[@attribute] matches the element name with atttribute "attribute"</li>
      <li>name[@attribute = 'value'] matches element "name" only if it has  attribute "attribute" with  "value"</li>
      <li></li> 
    </ul>

  </content>
</slide>
<!--================================================================-->




<slide>
 <title>
Template selections
 </title>
  <content>
    <ul>
      <li>&lt;xsl:apply-templates select="name" &gt; explicit call to template</li>
      <li>May be used more than once in different places of the stylesheet</li>
      <li>&lt;xsl:value-of select="name" &gt;</li>
      <li>Includes the evaluated content of "name" in the output</li>
      <li>All tags removed, entities resolved</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 Attributes in the output 
 </title>
  <content>
    <ul>
      <li>Create &lt;a href="http://www.iie.nl"&gt;http://www.iie.nl&lt;/a&gt;</li>
      <li>From: &lt;website&gt;http://www.iie.nl&lt;/website&gt;</li>
      <li>Using
<pre>
&lt;a href="&lt;xsl:value-of select='website'&gt;"&gt;website&lt;/a&gt;
</pre>

</li>
      <li>Is illegal: in XML no elements allowed in attributes</li>
<pre>
&lt;a href="{website}"&gt;website&lt;/a&gt;
</pre>      <li>does the job</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->





<slide>
 <title>
Reuse the same elements with different templates
 </title>
  <content>
    <ul>
      <li>Sometimes the same elements have to be processed in different ways</li>
      <li>Create Table-of-Contents or List-of-References</li>
      <li>Use template with mode-attribute</li>
      <li>&lt;apply-templates select="title" mode="ToC"/ &gt;</li>
      <li>&lt;apply-templates select="title" mode="Contents"/ &gt;</li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 Using mode-attribute on xsl:template 
 </title>
  <content>
<pre>
&lt;xsl:template match="Contributions"&gt;
&lt;ol&gt;
&lt;apply-templates select="Contribution" mode="ToC"/ &gt;
&lt;/ol&gt;

&lt;apply-templates select="Contribution" mode="Contents"/ &gt;  

&lt;/xsl:template&gt;

 
&lt;xsl:template match="Contribution" mode="ToC" &gt;
&lt;li&gt;&lt;xsl:value-of select="Title" /&gt; &lt;/li&gt; 
&lt;/xsl:template&gt;


&lt;xsl:template match="Contribution" mode="Contents" &gt;
&lt;h1&gt;&lt;xsl:value-of select="Title" /&gt; &lt;/h1&gt; 
&lt;xsl:apply-templates select="Content" /&gt; 
&lt;/xsl:template&gt;

</pre>

 
  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
  Conditional processing
 </title>
  <content>
   <ul>
      <li>If statement (no else):
 
<pre >
  &lt;xsl:if test="$condition"&gt;
  &lt;xsl:text&gt;print this text&lt;/xsl:text&gt;
&lt;/xsl:if&gt;
</pre>
</li>
      <li>
Choose  among alternatives with &lt;xsl:when&gt; and &lt;xsl:otherwise&gt;:

<pre>
&lt;xsl:choose&gt;
  &lt;xsl:when test="$count &gt; 2"&gt;&lt;xsl:text&gt;, and &lt;/xsl:text&gt;&lt;/xsl:when&gt;
  &lt;xsl:when test="$count &gt; 1"&gt;&lt;xsl:text&gt; and &lt;/xsl:text&gt;&lt;/xsl:when&gt;
  &lt;xsl:otherwise&gt;&lt;xsl:text&gt; &lt;/xsl:text&gt;&lt;/xsl:otherwise&gt;
&lt;/xsl:choose&gt;
</pre>
</li>
</ul>
   
  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
  Defining variables
 </title>
  <content>
    <ul>
      <li>&lt;xsl:variable&gt; allows you to associate a variable with
a string, node list, or result tree fragment</li>
      <li>Variables are "single assignment" </li>
      <li>You cannot change them</li>
      <li>Advantage: no side effects</li>
      <li>Variables are lexically scoped</li>
      <li>For instance used inside an if statement, they do no exist outside</li>
 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 Using variables 
 </title>
  <content>
    <ul>
      <li>Once assigned, variables can be used in XSL element attributes and templates</li>
      <li>XSL element attributes that expect an expression</li>
      <li>Attribute value templates: in the form "{$variable}"</li>
      <li></li>
      <li></li> 
    </ul>

  </content>
</slide>
<!--================================================================-->



<slide>
 <title>
 Counting and numbering
 </title>
  <content>
    <ul>
      <li>&lt;xsl:number&gt; can be used for counting and numbering</li>
      <li>It can evaluate an expression and format it
   <pre>
     &lt;xsl:number value="6+1" format="A. "/&gt;
     </pre>
 </li>
      <li>It can be used to count the number of elements and format them
    <pre>
&lt;xsl:number count="iteminlist" format="i. "/&gt;
&lt;xsl:number count="chapter" from="manual" level="any" format="1. "/&gt;
&lt;xsl:number count="h1|h2|h3" level="multiple" from="chapter|appendix" format="1."/&gt;
</pre>
 </li>
      <li>Many more possibilities to format the output</li>
      <li></li> 
    </ul>

  </content>
</slide>

<!--================================================================-->


<slide>
 <title>
  An elaborate example
 </title>
  <content>
    <ul>
      <li>Check-out the follwoing files for a longer examples</li>
      <li>An <a href="../../repository/music/music.xml"><font color="blue">XML-file</font></a> describing a music collection</li>
      <li>An <a href="../../repository/music/music.xsl"><font color="blue">XSL-file</font></a></li>
      <li>The result <a href="../../repository/music/music-out.html"><font color="blue">html-file</font></a></li>
      <li></li> 
    </ul>

  </content>
</slide>

-->
<!--================================================================-->

!--

<slide>
 <title>
  
 </title>
  <content>
    <ul>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li> 
    </ul>

  </content>
</slide>

-->

<!--================================================================-->

</slides> 

