Section 5.7.  Summary examples

  
Prev don't be afraid of buying books Next

5.7 Summary examples

5.7.1 Shared XSLT library

Example 5.19 is a compilation of code snippets from 5.1.1 , with a few additions and extensions. It is imported by our Schematron schemas (via the schematron-saxon.xsl wrapper, 5.1.2 ) and by the main transformation stylesheet that follows in Example 5.21.

Example 5.19. _lib.xsl : A shared XSLT library used by both the schema and the stylesheet.
 <  ?xml version="1.0" encoding="iso-8859-1"?  > <xsl:stylesheet     xmlns:xsl=  "http://www.w3.org/1999/XSL/Transform"  version=  "2.0"  xmlns:axsl=  "http://www.w3.org/1999/XSL/TransformAlias"  xmlns:xs=  "http://www.w3.org/2001/XMLSchema"  xmlns:saxon=  "http://saxon.sf.net/"  xmlns:eg=  "http://www.example.org/"  > <!--  Stylesheet parameters:  --> <!--  env specifies the environment where we run the stylesheet  --> <xsl:param name=  "env"  select=  "'final'"  /> <!--  images=yes turns image generation on  --> <xsl:param name=  "images"  select=  "'no'"  /> <!--  Master document:  --> <xsl:variable name=  "master"  select=  "document('_master.xml')"  /> <!--  Are we transforming the master document   (e.g., in batch processing)?  --> <xsl:variable name=  "this-master"  select=  "   boolean(/*[name()='site'])"  /> <!--  Source path for this environment:  --> <xsl:variable name=  "src-path"  select=  "   $master//environment[@id=$env]/src-path"  /> <!--  Path to the output directory:  --> <xsl:variable name=  "out-path"  select=  "   $master//environment[@id=$env]/out-path"  /> <!--  Target path, for src and href attributes in HTML:  --> <xsl:variable name=  "target-path"  select=  "   $master//environment[@id=$env]/target-path"  /> <!--  Image output directory, for accessing and generating images   during transformation:  --> <xsl:variable name=  "out-img"  >   <xsl:value-of select=  "$out-path"  />   <xsl:value-of select=  "$master//environment[@id = $env]/img-path"  />   <xsl:text>  /  </xsl:text> </xsl:variable> <!--  Image target directory, for image src attributes in HTML:  --> <xsl:variable name=  "target-img"  >   <xsl:value-of select=  "$target-path"  />   <xsl:value-of select=  "$master//environment[@id = $env]/img-path"  />   <xsl:text>  /  </xsl:text> </xsl:variable> <!--  Filename extensions:  --> <xsl:variable name=  "src-ext"  >  .xml  </xsl:variable> <xsl:variable name=  "out-ext"  >  .html  </xsl:variable> <!--  Current language, based on the current directory:  --> <xsl:variable name=  "lang"  >   <xsl:choose>     <xsl:when test=  "   substring-after(saxon:systemId(), $src-path) = ''"  >       <xsl:message terminate=  "yes"  >  Error: Source file path does not match $src-path   $env=  <xsl:value-of select=  "$env"  />  systemId =  <xsl:value-of select=  "saxon:systemId()"  />       </xsl:message>     </xsl:when>     <xsl:otherwise>       <xsl:value-of select=  "   substring-before(   substring-after(saxon:systemId(), $src-path),   '/')"  />     </xsl:otherwise>   </xsl:choose> </xsl:variable> <!--  Path to the current file (without extension)   starting from the root dir of the current language:  --> <xsl:variable name=  "current"  >   <xsl:choose>     <xsl:when test=  "   not($master//languages/lang = $lang)   and not($this-master)"  >       <xsl:message terminate=  "yes"  >  Error: Not in a valid language directory   $lang=  <xsl:value-of select=  "$lang"  />       </xsl:message>     </xsl:when>     <xsl:otherwise>       <xsl:value-of select=  "   substring-before(   substring-after(   substring-after(saxon:systemId(), $src-path),   concat($lang, '/')),   $src-ext)"  />     </xsl:otherwise>   </xsl:choose> </xsl:variable> <!--  True if the current page is the site's front page:  --> <xsl:variable name=  "frontpage"  select=  "$current = 'index'"  /> <!--  Unabbreviation functions:  --> <!--  Unabbreviate external links  --> <xsl:function name=  "eg:ext-link"  >   <xsl:param name=  "abbr"  />   <xsl:value-of select=  "   if (starts-with ($abbr, 'http://') or   starts-with ($abbr, 'ftp://'))   then $abbr   else concat('http://', $abbr)"  /> </xsl:function> <!--  Convert a file:/ URI into Windows native format  --> <xsl:function name=  "eg:os-path"  >   <xsl:param name=  "s"  />   <xsl:value-of select=  "   if (starts-with($s, 'file:/'))   then substring-after($s, 'file:/')   else $s"  /> </xsl:function> <!--  Return pathname of a page document  --> <xsl:function name=  "eg:page-src"  >   <xsl:param name=  "abbr"  />   <xsl:param name=  "lang"  />   <xsl:value-of select=  "   concat(   $src-path,   $lang, '/',   $master//(pageblock)[(@id,tokenize(@alias, '\s+')) = $abbr]   /@src,   $src-ext)"  /> </xsl:function> <!--  Return URI of a transformed HTML page  --> <xsl:function name=  "eg:page-link"  >   <xsl:param name=  "path"  />   <xsl:param name=  "abbr"  />   <xsl:param name=  "lang"  />   <xsl:value-of select=  "   concat(   $path,   $lang, '/',   $master//(pageblock)[(@id,tokenize(@alias, '\s+')) = $abbr]   /@src,   $out-ext)"  /> </xsl:function> </xsl:stylesheet> 

5.7.2 Advanced Schematron schema

Example 5.20 is a compilation of Schematron rules from 5.1.3 . You can run this as a separate schema to validate your source (both page documents and the master document), or you can combine it with Example 3.3 (page 149) into a single schema. Perhaps the only reason to keep this schema separate from the simpler schema of Chapter 3 is that the advanced checks are significantly slower because they search in many documents to validate all sorts of links and references.

Example 5.20. schema2.sch : An advanced Schematron schema to be used in conjunction with Example 3.3.
 <schema xmlns="http://www.ascc.net/xml/schematron"> <!--  Checks for the master document:  --> <pattern name="master"> <!--  Presence of page documents and orthogonal sources  --> <rule context="  menu//page  blocks/block  ">   <report test="  (for $l in $master//languages/lang   return boolean(document(eg:page-src(@id, $l))))   = false()  ">  A source document not found for  "<value-of select=  @id  "/>".   </report>   <assert test="  every $i in   (for  in $master//languages/lang   return (   if (@select)   then boolean(document(eg:page-src(@id, $l))   //block[@id=current()/@select])   else true()))   satisfies $i  ">  A block with @id="  <value-of select="  @select  "/>  " that the  "<value-of select="  @id  "/>  " orthogonal block refers to   is missing.  </assert> </rule> </pattern> <!--  Checks for page documents:  --> <pattern name="page"> <!--  Internal links  --> <rule context="  int  link[@linktype='internal']  ">   <assert test="  @link = (for $i in $master//(pageblock)/(@id@alias)   return tokenize($i, '\s+'))  ">  Broken internal link: no 'page' with   @id="  <value-of select="  @link  "/>  " in the   master document. Valid identifiers are:  <value-of select="  string-join(   (for $i in $master//(pageblock)/(@id@alias)   return tokenize($i, '\s+')), ', ')  "/>.   </assert> </rule> <!--  External links  --> <rule context="  ext  link[@linktype='external']  ">   <assert test="  boolean(unparsed-text(eg:ext-link(@link), 'iso-8859-1'))  ">  Broken external link:  <value-of select="  @link  "/>.   </assert> </rule> <!--  Language links  --> <rule context="  lang[not(ancestor::languages)]  link[@linktype='language']  ">   <assert test="  @link = $master//languages/lang  ">  Broken language link: no "  <value-of select="  @link  "/>  " language.  </assert> </rule> <!--  Orthogonal references  --> <rule context="  page//block[@idref]  ">   <assert test="  @idref = $master//blocks/block/@id  ">  A block with @idref must match the @id of one of the 'block'   elements in the master document.  </assert> </rule> <!--  Presence of images  --> <rule context="  section[@image]  ">   <assert test="  files:exists(eg:os-path(concat($out-img, @image, '.png')))  ">  Image file missing:  <value-of select="  concat($out-img, @image, '.png')  "/>.   </assert> </rule> <!--  Side-wide uniqueness of @id in p and head elements  --> <rule context="  p[@id]  head[@id]  ">   <assert test="  count(   for $src in distinct-values($master//(pageblock)/@src)   return   document(   concat($src-path, $lang, '/', $src, $src-ext))   //(phead)[@id=current()/@id])   = 1  ">  Non-unique @id in a 'p' or 'head':   @id="  <value-of select="  current()/@id  "/>  " is used in:  <value-of select="  string-join(   $master//(pageblock)[document(eg:page-src(@id, $lang))   //(phead)[@id=current()/@id]]/@src, ', ')  "/>.   </assert> </rule> </pattern> </schema> 

5.7.3 Stylesheet

Learning transformation techniques one bit at a time may be easy, but by now you may feel the urge to see how these bits really fit together. As promised , here's our Big Stylesheet Example (though it is actually small by the standards of many real projects). What is good about this example is that it is working and complete, including all the gory HTML layout details.

Components. This stylesheet builds upon our previous examples. Make sure you have the following software available:

  • _lib.xsl , our shared library of XSLT code (Example 5.19);

  • three of the extension Java classes we've been writing: files (Examples 5.6, 5.15), graph (Example 5.11), and text (Example 5.9); make sure the *.class files are in your CLASSPATH ;

  • the master document (Example 3.2);

  • a page document (you can use the one in Example 3.1 or write your own);

  • schema-compiled.xsl , a compiled Schematron schema (see 5.1.2 for compilation instructions); it is only required in the batch mode, and you can modify the template with mode="validate" to run a different validator, [32] or disable that template altogether;

    [32] If you prefer to rely on a DTD for validation ( 2.2.4 ), you don't need to do even thatjust make sure that your XML parser performs DTD validation before passing the document to the XSLT processor. With Saxon, this is done by specifying the -v command-line option.

  • a font in SVG format, if you plan to run the stylesheet with images=yes ; refer to 5.5.2 for instructions on how to create one, and replace pushkin.svg in the stylesheet by the name of your font file.

Processor. You'll also need an XSLT 2.0 processor (the code was tested on Saxon 7.5.1 under Linux and Windows). The _lib.xsl library uses one Saxon-specific extension, saxon:systemId() ; however, similar functions are offered by other processors, so porting the stylesheet away from Saxon should not be a problem. The XSLT 2.0 requirement, on the other hand, is hardly possible to lift, as the stylesheet uses a lot of 2.0 features.

Graphic software. The image creation template uses Batik (tested with version 1.5). Make sure the batik- rasterizer .jar file is in your Java CLASSPATH . You'll also need Imagemagick (tested with version 5.4.8); its command-line utilities must be in your operating system's executable path.

Windows paths. Unfortunately, under Windows, neither Imagemagick nor Batik recognize Windows pathnames in the URL format (e.g., file:/C:/Work/Website/image.png ). On the other hand, some browsers on Windows can only understand URLs with file:/ because otherwise they mistake the drive letter for a URL protocol. Therefore, in the master document we store Windows pathnames in the URL format, but in the create-image template we need to remove the file:/ prefix if it is present. This is done by calling the eg:os-path() function defined in _lib.xsl (Example 5.19). If you don't plan to run your stylesheet on Windows, you can happily drop this function altogether and use the $svg and $png variables directly.

Deployment. Here's the command used to run this stylesheet on a single page document, using Saxon 7:


 saxon -o  output input  style.xsl env=  env  images={yesno} 


Here, style.xsl is the name of the stylesheet file, input and output are the pathnames of the input (XML) and output (HTML) files correspondingly. The default value of the images parameter is no . For example, for an English version of team/index in the staging environment, without image generation, the command would look like this:


 saxon -o out/en/team/index.html en/team/index.xml style.xsl env=staging 


The pathnames here are relative, assuming you run this command from the root of the input directory tree (for staging , it is /home/d/web/ , see Example 3.2 on page 143).

To run the stylesheet in batch mode ( 5.6 ), all you need to do is


 saxon  master  style.xsl env=  env  images={yesno} 


where master is the pathname of the master document. If everything goes as planned, a batch run of the stylesheet will first display a stream of validation diagnostic messages (including any errors found in individual page documents):


 Validating /home/d/web/en/index.xml Validating /home/d/web/de/index.xml Validating /home/d/web/en/solutions/intro_solutions.xml Validating /home/d/web/de/solutions/intro_solutions.xml Validating /home/d/web/en/solutions/life.xml Line 32:    Non-unique @id in a 'p' or 'head': @id="foo" is used in:    solutions/life, team/hire. Validating /home/d/web/de/solutions/life.xml Validating /home/d/web/en/team/index.xml Validating /home/d/web/de/team/index.xml Validating /home/d/web/en/team/history.xml Line 26:    Broken internal link: no 'page' with @id="bar" in the    master document. ... 


After all pages are validated , batch transformation starts with its own diagnostic messages:


 Transforming /home/d/web/en/index.xml processing: index     lang: en     env: staging     src-path: /home/d/web/     out-path: /home/d/web/out/ creating: site.css Transforming /home/d/web/de/index.xml processing: index     lang: de     env: staging     src-path: /home/d/web/     out-path: /home/d/web/out/ creating: site.css ... 


Layout overview. Compared to the examples scattered throughout the chapter, this stylesheet is more complex in some aspects but simpler in others, as we don't need every trick discussed so far to build a simple web page out of Example 3.1. The stylesheet builds a tablebased, stretchable subpage layout (no effort was made to accommodate a different front page layout) with the following areas:

  • logo area in the top left corner (static content, fixed width);

  • top menu listing the site's top-level sections (built dynamically from the master document data, including image generation for item labels);

  • side menu listing the branch of the site's tree to which the current page belongs (generated dynamically from the master document data);

  • main content area (generated from the current page document, stretches to fill all available window width);

  • footer stuffcopyright notice, etc. (supplied by the master document);

  • orthogonal blocks area (orthogonal block references are on the current page; content may be taken from other pages).

In the main content blocks and orthogonal blocks, the section template builds a simple structure with a heading, subheading , optionally an image, and a sequence of paragraphs. All formatting properties are expressed via CSS. The browser screenshot of the final transformed page is shown in Figure 5.3.

Figure 5.3. The result of transforming the page document from Example 3.1 with the stylesheet from Example 5.21, using Example 3.2 as master document and Example 5.19 as shared library.
graphics/05fig03.jpg




Don't ask me why. If you want the generated PNG files to be viewable in Microsoft Internet Explorer, add -bg 254.255.255.255 to the Batik call (after the class name).

Example 5.21. style.xsl : A summary stylesheet example using many techniques discussed in this chapter.
 <  ?xml version="1.0" encoding="iso-8859-1"?  > <  !DOCTYPE xsl:stylesheet [  <  !ENTITY copy "&#169;"  >   <  !ENTITY nbsp "&#160;"  >   <  !ENTITY mdash "&#8212;"  >  ]  > <xsl:stylesheet     xmlns:xsl=  "http://www.w3.org/1999/XSL/Transform"  version=  "2.0"  xmlns:eg=  "http://www.example.org/"  xmlns:files=  "com.projectname.xslt.files"  xmlns:graph=  "com.projectname.xslt.graph"  xmlns:text=  "com.projectname.xslt.text"  extension-element-prefixes=  "eg files graph text"  > <xsl:import href=  "_lib.xsl"  /> <xsl:output method=  "html"  encoding=  "US-ASCII"  indent=  "no"  doctype-public=  "-//W3C//DTD HTML 4.0 Transitional//EN"  /> <xsl:output name=  "txt"  method=  "text"  encoding=  "iso-8859-1"  omit-xml-declaration=  "yes"  /> <xsl:output name=  "xml"  method=  "xml"  encoding=  "iso-8859-1"  indent=  "yes"  /> <!--  Page skeleton  --> <xsl:template match=  "/page"  >   <xsl:message>  processing:  <xsl:value-of select=  "$current"  />  lang:  <xsl:value-of select=  "$lang"  />  env:  <xsl:value-of select=  "$env"  />  src-path:  <xsl:value-of select=  "$src-path"  />  out-path:  <xsl:value-of select=  "$out-path"  />  target-path:  <xsl:value-of select=  "$target-path"  />   </xsl:message>   <!--  Credits are in XML comments,   so they can come before the root element:  -->   <xsl:call-template name=  "credits"  />   <html>     <head>       <xsl:apply-templates select=  "@keywords  @description"  />       <xsl:call-template name=  "title"  />       <xsl:call-template name=  "css"  />     </head>     <body>       <table style="table-layout: fixed; width: 100%;">         <tr>           <td style="width: 150px;">             <!--  logo cell  -->             <xsl:variable name=  "logo"  select=  "   concat($out-img, 'logo.png')"  />             <img src="  {concat($target-img, 'logo.png')}  "               width="  {graph:getw($logo)}  "               height="  {graph:geth($logo)}  "               alt="  {$master//html-title/translation[@lang=$lang]}  "/>           </td>           <td>             <!--  top menu cell  -->             <xsl:call-template name=  "top-menu"  />           </td>         </tr>         <tr>           <td style="width: 150px; vertical-align: top;">             <!--  side menu cell  -->             <xsl:call-template name=  "side-menu"  />           </td>           <td style="margin: 1em; padding-left: 1em; padding-top: 1em;             border-left: 2px dotted; border-color: #003399;             vertical-align: top;">             <!--  body area  -->             <xsl:apply-templates select=  "block[not(@idref)]"  />           </td>         </tr>         <tr>           <td style="width: 150px; vertical-align: top;">             <!--  page-footer cell  -->             <xsl:call-template name=  "page-footer"  />           </td>           <td>             <!--  orthogonal content area  -->             <table width="100%" style="border-spacing: 1.2em;">               <tr bgcolor="#ffffff">                 <xsl:apply-templates select=  "block[@idref]"  />               </tr>             </table>           </td>         </tr>       </table>     </body>   </html> </xsl:template> <!--  Static templates  --> <xsl:template name=  "credits"  >   <xsl:comment>  XSLT programming by Ed N. Gineer, ed at foobar dot com  </xsl:comment> </xsl:template> <xsl:template match=  "page/@description"  >   <meta name="description" content="  {.}  "/> </xsl:template> <xsl:template match=  "page/@keywords"  >   <meta name="keywords" content="  {.}  "/> </xsl:template> <xsl:template name=  "title"  >   <title>     <xsl:value-of select=  "   $master//html-title/translation[@lang=$lang]/text()"  />     <xsl:text>: </xsl:text><xsl:value-of select=  "title/text()"  />   </title> </xsl:template> <xsl:template name=  "css"  >   <link rel="stylesheet" href="  {$target-path}  site.css"/>   <xsl:message>  creating:site.css  </xsl:message>   <xsl:result-document href=  "file:///{$out-path}site.css"  format=  "txt"  >  body {font-family: serif; background-color: #ffffff;}   h1 {font-family: sans-serif; font-size: 120%; font-weight: normal;}   h2 {font-size: 100%; font-weight: normal; font-style: italic;}   .inactive {border: 0em; padding-bottom: 4px; border-bottom: 2px dotted;}   .active {border: 0em; padding-bottom: 4px; border: 0px ! important;}   a {text-decoration: none; border-bottom: 2px dotted; color: #003399;}   .footer {font-size: 80%; margin-top: 1em; margin-left: 0.5em;}   .sideitem {text-align: middle; font-size: 70%; padding-top: 2em;   margin: 0.5em; text-transform: uppercase;}  </xsl:result-document> </xsl:template> <!--  Footer stuff  --> <xsl:template name=  "page-footer"  >   <xsl:apply-templates select=  "$master//page-footer/*"  /> </xsl:template> <xsl:template match=  "page-footer/*"  >   <p class="footer">     <xsl:apply-templates select=  "translation[@lang=$lang]"  />   </p> </xsl:template> <!--  Menus  --> <xsl:template name=  "side-menu"  >   <xsl:apply-templates select=  "   $master//menu//item[page/@src = $current]/(pageitem)"  mode=  "side"  /> </xsl:template> <xsl:template name=  "top-menu"  >   <xsl:apply-templates select=  "$master//menu/item"  mode=  "top"  /> </xsl:template> <xsl:template match=  "menu/item"  mode=  "top"  >   <xsl:variable name=  "src"  select=  "page[1]/@src"  />   <xsl:variable name=  "label"  select=  "   label/translation[@lang=$lang]"  />   <xsl:variable name=  "filename"  select=  "   concat(   string(1 + count(preceding-sibling::*)),   eg:letters-only($label))"  />   <xsl:if test=  "$images='yes'"  >     <xsl:call-template name=  "create-image"  >       <xsl:with-param name=  "label"  select=  "$label"  />       <xsl:with-param name=  "filename"  select=  "   concat($out-img, $filename)"  />     </xsl:call-template>   </xsl:if>   <xsl:choose>     <xsl:when test=  "$src = $current"  >       <span class="active">         <img src="  {$target-img}{$filename}  .png" alt="  {$label}  "            style="padding: 35px;"            width="  {graph:getw(concat($out-img, $filename, '.png'))}  "            height="  {graph:geth(concat($out-img, $filename, '.png'))}  "/>       </span>     </xsl:when>     <xsl:when test=  "   ($src != $current) and   (.//page/@src = $current)"  >       <a href="  {$target-path}{$lang}  /  {$src}{$out-ext}  "          class="active">         <img src="  {$target-img}{$filename}  .png" alt="  {$label}  "            border="0" style="padding: 35px;"            width="  {graph:getw(concat($out-img, $filename, '.png'))}  "            height="  {graph:geth(concat($out-img, $filename, '.png'))}  "/>       </a>     </xsl:when>     <xsl:otherwise>       <a href="  {$target-path}{$lang}/{$src}{$out-ext}"  class="inactive">         <img src="  {$target-img}{$filename}  .png" alt="  {$label}  "            border="0" style="padding: 35px;"            width="  {graph:getw(concat($out-img, $filename, '.png'))}  "            height="  {graph:geth(concat($out-img, $filename, '.png'))}  "/>       </a>     </xsl:otherwise>   </xsl:choose> </xsl:template> <xsl:template match=  "menu//item/*"  mode=  "side"  >   <xsl:variable name=  "src"  select=  "   if (self::item) then page[1]/@src else @src"  />   <xsl:variable name=  "label"  select=  "   if (self::item)   then label/translation[@lang=$lang]   else document(string(eg:page-src(@id, $lang)))//title"  />   <xsl:choose>     <xsl:when test=  "$src = $current"  >       <div class="sideitem"><xsl:value-of select=  "$label"  /></div>     </xsl:when>     <xsl:otherwise>       <div class="sideitem">         <a href="  {$target-path}{$lang}/{$src}{$out-ext}  ">           <xsl:value-of select=  "$label"  />         </a>       </div>     </xsl:otherwise>   </xsl:choose> </xsl:template> <!--  Blocks and sections  --> <xsl:template match=  "block[@idref]"  >   <xsl:variable name=  "doc"  select=  "   document(string(eg:page-src(@idref, $lang)))"  />   <xsl:variable name=  "select"  select=  "   $master//block[@id=current()/@idref]/@select"  />   <xsl:variable name=  "from"  select=  "   if ($select)   then $doc//block[@id=$select]   else $doc//block[1]"  />   <td style="margin-left: 1em; vertical-align: top; width: 50%;      border: 2px dotted; border-color: #003399;">     <div style="padding: 0.3em;">       <xsl:apply-templates select=  "$from//section  $from/p"  />     </div>   </td> </xsl:template> <xsl:template match=  "block[not(@idref)]"  >   <xsl:apply-templates select=  "section  p"  /> </xsl:template> <xsl:template match=  "section"  >   <table style="margin-bottom: 1em;">     <tr>       <td style="vertical-align: top;">         <!--  image cell  -->         <xsl:if test=  "@image"  >           <img src="  {$target-img}{@image}  .png" alt="  {head}  "/>         </xsl:if>       </td>       <td>         <h1><xsl:apply-templates select=  "head"  /></h1>         <h2><xsl:apply-templates select=  "subhead"  /></h2>         <xsl:apply-templates select=  "p"  />       </td>     </tr>   </table> </xsl:template> <!--  Image generation  --> <xsl:function name=  "eg:letters-only"  >   <xsl:param name=  "s"  />   <!--  remove punctuation, replace German accented letters  -->   <xsl:value-of select=  "   translate(   lower-case(replace($s, '\ ,\.!\?',  '')),   '&#xc4;&#xd6;&#xdc;&#xe4;&#xf6;&#xfc;',   'aouaou')"  /> </xsl:function> <xsl:template name=  "create-image"  >   <xsl:param name=  "label"  />   <xsl:param name=  "filename"  />   <xsl:variable name=  "svg"  select=  "concat($filename, '.svg')"  />   <xsl:variable name=  "png"  select=  "concat($filename, '.png')"  />   <xsl:result-document href=  "file:///{$svg}"  format=  "xml"  >     <svg width="500px" height="100px"        xmlns="http://www.w3.org/2000/svg"        xmlns:xlink="http://www.w3.org/1999/xlink">       <defs>         <font-face font-family="Pushkin">           <font-face-src>             <font-face-uri               xlink:href="  {$src-path}  pushkin.svg#font"/>           </font-face-src>         </font-face>       </defs>       <text style="          fill: #000000; font-family: Pushkin; font-size: 30px;"          x="10px" y="50px">         <xsl:value-of select=  "$label"  />       </text>     </svg>   </xsl:result-document>   <xsl:message>     <xsl:value-of select=  "   files:run(   concat(   'java org.apache.batik.apps.rasterizer.Main ',   eg:os-path($svg)))"  />   </xsl:message>   <xsl:message>     <xsl:value-of select=  "   files:run(concat('mogrify -trim ', eg:os-path($png)))"  />   </xsl:message> </xsl:template> <!--  Text markup  --> <xsl:template match=  "p"  >   <p><xsl:apply-templates/></p> </xsl:template> <xsl:template match=  "em"  >   <em><xsl:apply-templates/></em> </xsl:template> <!--  Links  --> <xsl:template match=  "link[@linktype='internal']  int"  >   <a href="  {eg:page-link($target-path, @link, $lang)}  ">     <xsl:apply-templates/>   </a> </xsl:template> <xsl:template match=  "link[@linktype='external']  ext"  >   <a href="  {eg:ext-link(@link)}  ">     <xsl:apply-templates/>   </a> </xsl:template> <xsl:template match=  "link[@linktype='mailto']  mailto"  >   <a href="mailto:  {@link}  ">     <xsl:apply-templates/>   </a> </xsl:template> <xsl:template match=  "link[@linktype='lang']  lang"  >   <a href="  {$target-path}{@link}/{$current}{$out-ext}  ">     <xsl:apply-templates/>   </a> </xsl:template> <!--  Typography  --> <xsl:template match=  "p//text()  head//text()  subhead//text()"  >   <xsl:value-of select=  "text:typography(.)"  /> </xsl:template> <!--  Batch processing  --> <xsl:template match=  "/site"  >   <xsl:result-document       href=  "file:///{eg:os-path($src-path)}validate-commands.log"  format=  "txt"  >     <xsl:apply-templates select=  "menu//page"  mode=  "validate"  />   </xsl:result-document>   <xsl:result-document       href=  "file:///{eg:os-path($src-path)}transform-commands.log"  format=  "txt"  >     <xsl:apply-templates select=  "menu//page"  mode=  "transform"  />   </xsl:result-document> </xsl:template> <xsl:template match=  "page"  mode=  "validate"  >   <xsl:variable name=  "id"  select=  "@id"  />   <xsl:for-each select=  "$master//languages/lang"  >     <xsl:message>  Validating  <xsl:value-of select=  "eg:page-src($id, .)"  />     </xsl:message>     <xsl:value-of select=  "   files:run(concat(   'java net.sf.saxon.Transform -l ',   eg:os-path(eg:page-src($id, .)),   ' schema-compiled.xsl',   ' env=', $env   ))"  />   </xsl:for-each> </xsl:template> <xsl:template match=  "page"  mode=  "transform"  >   <xsl:variable name=  "id"  select=  "@id"  />   <xsl:for-each select=  "$master//languages/lang"  >     <xsl:message>  Transforming  <xsl:value-of select=  "eg:page-src($id, .)"  />     </xsl:message>     <xsl:value-of select=  "   files:run(concat(   'java net.sf.saxon.Transform ',   '-o ', eg:os-path(eg:page-link($out-path, $id, .)),   ' ', eg:os-path(eg:page-src($id, .)),   ' style.xsl',   ' env=', $env,   ' images=', if ($id='home') then $images else 'no'   ))"  />   </xsl:for-each> </xsl:template> </xsl:stylesheet> 

 
  
Amazon


XSLT 2.0 Web Development
ASP.Net 2.0 Cookbook (Cookbooks (OReilly))
ISBN: 0596100647
EAN: 2147483647
Year: 2006
Pages: 90

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net