home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _5E3B068961744B31AE1858E5EC6CE24D < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-04  |  7.0 KB  |  191 lines

  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2.                 xmlns:saxon="http://icl.com/saxon"
  3.                 xmlns:lxslt="http://xml.apache.org/xslt"
  4.                 xmlns:xalanredirect="org.apache.xalan.xslt.extensions.Redirect"
  5.                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  6.         version="1.1"
  7.                 exclude-result-prefixes="doc"
  8.                 extension-element-prefixes="saxon xalanredirect lxslt">
  9.  
  10. <!-- This stylesheet works with Saxon and Xalan; for XT use xtchunker.xsl -->
  11.  
  12. <!-- ==================================================================== -->
  13.  
  14. <xsl:param name="default.encoding" select="'ISO-8859-1'" doc:type='string'/>
  15.  
  16. <doc:param name="default.encoding" xmlns="">
  17. <refpurpose>Encoding used in generated HTML pages</refpurpose>
  18. <refdescription>
  19. <para>This encoding is used in files generated by chunking stylesheet. Currently
  20. only Saxon is able to change output encoding.
  21. </para>
  22. </refdescription>
  23. </doc:param>
  24.  
  25. <!-- ==================================================================== -->
  26.  
  27. <xsl:param name="saxon.character.representation" select="'entity;decimal'" doc:type='string'/>
  28.  
  29. <doc:param name="saxon.character.representation" xmlns="">
  30. <refpurpose>Saxon character representation used in generated HTML pages</refpurpose>
  31. <refdescription>
  32. <para>This character representation is used in files generated by chunking stylesheet. If
  33. you want to suppress entity references for characters with direct representation 
  34. in default.encoding, set this parameter to value <literal>native</literal>. 
  35. </para>
  36. </refdescription>
  37. </doc:param>
  38.  
  39. <!-- ==================================================================== -->
  40.  
  41. <xsl:template name="make-relative-filename">
  42.   <xsl:param name="base.dir" select="'./'"/>
  43.   <xsl:param name="base.name" select="''"/>
  44.  
  45.   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  46.  
  47.   <xsl:choose>
  48.     <xsl:when test="contains($vendor, 'SAXON')">
  49.       <!-- Saxon doesn't make the chunks relative -->
  50.       <xsl:value-of select="concat($base.dir,$base.name)"/>
  51.     </xsl:when>
  52.     <xsl:when test="contains($vendor, 'Apache')">
  53.       <!-- Xalan doesn't make the chunks relative -->
  54.       <xsl:value-of select="concat($base.dir,$base.name)"/>
  55.     </xsl:when>
  56.     <xsl:otherwise>
  57.       <xsl:message terminate="yes">
  58.         <xsl:text>Chunking isn't supported with </xsl:text>
  59.         <xsl:value-of select="$vendor"/>
  60.       </xsl:message>
  61.     </xsl:otherwise>
  62.   </xsl:choose>
  63. </xsl:template>
  64.  
  65. <xsl:template name="write.chunk">
  66.   <xsl:param name="filename" select="''"/>
  67.   <xsl:param name="method" select="'html'"/>
  68.   <xsl:param name="encoding" select="$default.encoding"/>
  69.   <xsl:param name="indent" select="'no'"/>
  70.   <xsl:param name="content" select="''"/>
  71.  
  72.   <xsl:message>
  73.     <xsl:text>Writing </xsl:text>
  74.     <xsl:value-of select="$filename"/>
  75.     <xsl:if test="name(.) != ''">
  76.       <xsl:text> for </xsl:text>
  77.       <xsl:value-of select="name(.)"/>
  78.       <xsl:if test="@id">
  79.         <xsl:text>(</xsl:text>
  80.         <xsl:value-of select="@id"/>
  81.         <xsl:text>)</xsl:text>
  82.       </xsl:if>
  83.     </xsl:if>
  84.   </xsl:message>
  85.  
  86.   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  87.  
  88.   <xsl:choose>
  89.     <xsl:when test="contains($vendor, 'SAXON 6.2')">
  90.       <!-- Saxon 6.2.x uses xsl:document -->
  91.       <xsl:document href="{$filename}"
  92.                     method="{$method}"
  93.                     encoding="{$encoding}"
  94.                     indent="{$indent}"
  95.                     saxon:character-representation="{$saxon.character.representation}">
  96.         <xsl:copy-of select="$content"/>
  97.       </xsl:document>
  98.     </xsl:when>
  99.     <xsl:when test="contains($vendor, 'SAXON')">
  100.       <!-- Saxon uses saxon:output -->
  101.       <saxon:output file="{$filename}"
  102.                     href="{$filename}"
  103.                     method="{$method}"
  104.                     encoding="{$encoding}"
  105.                     indent="{$indent}"
  106.                     saxon:character-representation="{$saxon.character.representation}">
  107.         <xsl:copy-of select="$content"/>
  108.       </saxon:output>
  109.     </xsl:when>
  110.     <xsl:when test="contains($vendor, 'Apache')">
  111.       <!-- Xalan uses xalanredirect -->
  112.       <xalanredirect:write file="{$filename}">
  113.         <xsl:copy-of select="$content"/>
  114.       </xalanredirect:write>
  115.     </xsl:when>
  116.     <xsl:otherwise>
  117.       <!-- it doesn't matter since we won't be making chunks... -->
  118.       <xsl:message terminate="yes">
  119.         <xsl:text>Can't make chunks with </xsl:text>
  120.         <xsl:value-of select="$vendor"/>
  121.         <xsl:text>'s processor.</xsl:text>
  122.       </xsl:message>
  123.     </xsl:otherwise>
  124.   </xsl:choose>
  125. </xsl:template>
  126.  
  127. <xsl:template name="write.chunk.with.doctype">
  128.   <xsl:param name="filename" select="''"/>
  129.   <xsl:param name="method" select="'html'"/>
  130.   <xsl:param name="encoding" select="$default.encoding"/>
  131.   <xsl:param name="indent" select="'no'"/>
  132.   <xsl:param name="doctype-public" select="''"/>
  133.   <xsl:param name="doctype-system" select="''"/>
  134.   <xsl:param name="content" select="''"/>
  135.  
  136.   <xsl:message>
  137.     <xsl:text>Writing </xsl:text>
  138.     <xsl:value-of select="$filename"/>
  139.     <xsl:if test="name(.) != ''">
  140.       <xsl:text> for </xsl:text>
  141.       <xsl:value-of select="name(.)"/>
  142.     </xsl:if>
  143.   </xsl:message>
  144.  
  145.   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  146.  
  147.   <xsl:choose>
  148.     <xsl:when test="contains($vendor, 'SAXON 6.2')">
  149.       <!-- Saxon 6.2.x uses xsl:document -->
  150.       <xsl:document href="{$filename}"
  151.                     method="{$method}"
  152.                     encoding="{$encoding}"
  153.                     indent="{$indent}"
  154.                     doctype-public="{$doctype-public}"
  155.                     doctype-system="{$doctype-system}"
  156.                     saxon:character-representation="{$saxon.character.representation}">
  157.         <xsl:copy-of select="$content"/>
  158.       </xsl:document>
  159.     </xsl:when>
  160.     <xsl:when test="contains($vendor, 'SAXON')">
  161.       <!-- Saxon uses saxon:output -->
  162.       <saxon:output file="{$filename}"
  163.                     href="{$filename}"
  164.                     method="{$method}"
  165.                     encoding="{$encoding}"
  166.                     indent="{$indent}"
  167.                     doctype-public="{$doctype-public}"
  168.                     doctype-system="{$doctype-system}"
  169.                     saxon:character-representation="{$saxon.character.representation}">
  170.         <xsl:copy-of select="$content"/>
  171.       </saxon:output>
  172.     </xsl:when>
  173.     <xsl:when test="contains($vendor, 'Apache')">
  174.       <!-- Xalan uses xalanredirect -->
  175.       <xalanredirect:write file="{$filename}">
  176.         <xsl:copy-of select="$content"/>
  177.       </xalanredirect:write>
  178.     </xsl:when>
  179.     <xsl:otherwise>
  180.       <!-- it doesn't matter since we won't be making chunks... -->
  181.       <xsl:message terminate="yes">
  182.         <xsl:text>Can't make chunks with </xsl:text>
  183.         <xsl:value-of select="$vendor"/>
  184.         <xsl:text>'s processor.</xsl:text>
  185.       </xsl:message>
  186.     </xsl:otherwise>
  187.   </xsl:choose>
  188. </xsl:template>
  189.  
  190. </xsl:stylesheet>
  191.