home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _46A2A162135E45FF9F23A9A6A61A27EA < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-04  |  19.6 KB  |  411 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:exsl="http://exslt.org/common"
  6.                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  7.         version="1.1"
  8.                 exclude-result-prefixes="doc"
  9.                 extension-element-prefixes="saxon xalanredirect lxslt exsl">
  10.  
  11. <!-- This stylesheet works with XSLT implementations that support -->
  12. <!-- exsl:document, saxon:output, or xalanredirect:write -->
  13. <!-- Note: Only Saxon 6.4.2 or later is supported. -->
  14.  
  15. <xsl:param name="chunker.output.method" select="'html'"/>
  16. <xsl:param name="chunker.output.encoding" select="'ISO-8859-1'"/>
  17. <xsl:param name="chunker.output.indent" select="'no'"/>
  18. <xsl:param name="chunker.output.omit-xml-declaration" select="'no'"/>
  19. <xsl:param name="chunker.output.standalone" select="'no'"/>
  20. <xsl:param name="chunker.output.doctype-public" select="''"/>
  21. <xsl:param name="chunker.output.doctype-system" select="''"/>
  22. <xsl:param name="chunker.output.media-type" select="''"/>
  23. <xsl:param name="chunker.output.cdata-section-elements" select="''"/>
  24.  
  25. <xsl:param name="saxon.character.representation" select="'entity;decimal'"/>
  26.  
  27. <!-- ==================================================================== -->
  28.  
  29. <xsl:template name="make-relative-filename">
  30.   <xsl:param name="base.dir" select="'./'"/>
  31.   <xsl:param name="base.name" select="''"/>
  32.  
  33.   <xsl:choose>
  34.     <!-- put Saxon first to work around a bug in libxslt -->
  35.     <xsl:when test="element-available('saxon:output')">
  36.       <!-- Saxon doesn't make the chunks relative -->
  37.       <xsl:value-of select="concat($base.dir,$base.name)"/>
  38.     </xsl:when>
  39.     <xsl:when test="element-available('exsl:document')">
  40.       <!-- EXSL document does make the chunks relative, I think -->
  41.       <xsl:choose>
  42.         <xsl:when test="count(parent::*) = 0">
  43.           <xsl:value-of select="concat($base.dir,$base.name)"/>
  44.         </xsl:when>
  45.         <xsl:otherwise>
  46.           <xsl:value-of select="$base.name"/>
  47.         </xsl:otherwise>
  48.       </xsl:choose>
  49.     </xsl:when>
  50.     <xsl:when test="element-available('xalanredirect:write')">
  51.       <!-- Xalan doesn't make the chunks relative -->
  52.       <xsl:value-of select="concat($base.dir,$base.name)"/>
  53.     </xsl:when>
  54.     <xsl:otherwise>
  55.       <xsl:message terminate="yes">
  56.         <xsl:text>Don't know how to chunk with </xsl:text>
  57.         <xsl:value-of select="system-property('xsl:vendor')"/>
  58.       </xsl:message>
  59.     </xsl:otherwise>
  60.   </xsl:choose>
  61. </xsl:template>
  62.  
  63. <xsl:template name="write.chunk">
  64.   <xsl:param name="filename" select="''"/>
  65.   <xsl:param name="quiet" select="0"/>
  66.  
  67.   <xsl:param name="method" select="$chunker.output.method"/>
  68.   <xsl:param name="encoding" select="$chunker.output.encoding"/>
  69.   <xsl:param name="indent" select="$chunker.output.indent"/>
  70.   <xsl:param name="omit-xml-declaration"
  71.              select="$chunker.output.omit-xml-declaration"/>
  72.   <xsl:param name="standalone" select="$chunker.output.standalone"/>
  73.   <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  74.   <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  75.   <xsl:param name="media-type" select="$chunker.output.media-type"/>
  76.   <xsl:param name="cdata-section-elements"
  77.              select="$chunker.output.cdata-section-elements"/>
  78.  
  79.   <xsl:param name="content"/>
  80.  
  81.   <xsl:if test="$quiet = 0">
  82.     <xsl:message>
  83.       <xsl:text>Writing </xsl:text>
  84.       <xsl:value-of select="$filename"/>
  85.       <xsl:if test="name(.) != ''">
  86.         <xsl:text> for </xsl:text>
  87.         <xsl:value-of select="name(.)"/>
  88.         <xsl:if test="@id">
  89.           <xsl:text>(</xsl:text>
  90.           <xsl:value-of select="@id"/>
  91.           <xsl:text>)</xsl:text>
  92.         </xsl:if>
  93.       </xsl:if>
  94.     </xsl:message>
  95.   </xsl:if>
  96.  
  97.   <xsl:choose>
  98.     <xsl:when test="element-available('exsl:document')">
  99.       <xsl:choose>
  100.         <!-- Handle the permutations ... -->
  101.         <xsl:when test="$media-type != ''">
  102.           <xsl:choose>
  103.             <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  104.               <exsl:document href="{$filename}"
  105.                              method="{$method}"
  106.                              encoding="{$encoding}"
  107.                              indent="{$indent}"
  108.                              omit-xml-declaration="{$omit-xml-declaration}"
  109.                              cdata-section-elements="{$cdata-section-elements}"
  110.                              media-type="{$media-type}"
  111.                              doctype-public="{$doctype-public}"
  112.                              doctype-system="{$doctype-system}"
  113.                              standalone="{$standalone}">
  114.                 <xsl:copy-of select="$content"/>
  115.               </exsl:document>
  116.             </xsl:when>
  117.             <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  118.               <exsl:document href="{$filename}"
  119.                              method="{$method}"
  120.                              encoding="{$encoding}"
  121.                              indent="{$indent}"
  122.                              omit-xml-declaration="{$omit-xml-declaration}"
  123.                              cdata-section-elements="{$cdata-section-elements}"
  124.                              media-type="{$media-type}"
  125.                              doctype-public="{$doctype-public}"
  126.                              standalone="{$standalone}">
  127.                 <xsl:copy-of select="$content"/>
  128.               </exsl:document>
  129.             </xsl:when>
  130.             <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  131.               <exsl:document href="{$filename}"
  132.                              method="{$method}"
  133.                              encoding="{$encoding}"
  134.                              indent="{$indent}"
  135.                              omit-xml-declaration="{$omit-xml-declaration}"
  136.                              cdata-section-elements="{$cdata-section-elements}"
  137.                              media-type="{$media-type}"
  138.                              doctype-system="{$doctype-system}"
  139.                              standalone="{$standalone}">
  140.                 <xsl:copy-of select="$content"/>
  141.               </exsl:document>
  142.             </xsl:when>
  143.             <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  144.               <exsl:document href="{$filename}"
  145.                              method="{$method}"
  146.                              encoding="{$encoding}"
  147.                              indent="{$indent}"
  148.                              omit-xml-declaration="{$omit-xml-declaration}"
  149.                              cdata-section-elements="{$cdata-section-elements}"
  150.                              media-type="{$media-type}"
  151.                              standalone="{$standalone}">
  152.                 <xsl:copy-of select="$content"/>
  153.               </exsl:document>
  154.             </xsl:otherwise>
  155.           </xsl:choose>
  156.         </xsl:when>
  157.         <xsl:otherwise>
  158.           <xsl:choose>
  159.             <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  160.               <exsl:document href="{$filename}"
  161.                              method="{$method}"
  162.                              encoding="{$encoding}"
  163.                              indent="{$indent}"
  164.                              omit-xml-declaration="{$omit-xml-declaration}"
  165.                              cdata-section-elements="{$cdata-section-elements}"
  166.                              doctype-public="{$doctype-public}"
  167.                              doctype-system="{$doctype-system}"
  168.                              standalone="{$standalone}">
  169.                 <xsl:copy-of select="$content"/>
  170.               </exsl:document>
  171.             </xsl:when>
  172.             <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  173.               <exsl:document href="{$filename}"
  174.                              method="{$method}"
  175.                              encoding="{$encoding}"
  176.                              indent="{$indent}"
  177.                              omit-xml-declaration="{$omit-xml-declaration}"
  178.                              cdata-section-elements="{$cdata-section-elements}"
  179.                              doctype-public="{$doctype-public}"
  180.                              standalone="{$standalone}">
  181.                 <xsl:copy-of select="$content"/>
  182.               </exsl:document>
  183.             </xsl:when>
  184.             <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  185.               <exsl:document href="{$filename}"
  186.                              method="{$method}"
  187.                              encoding="{$encoding}"
  188.                              indent="{$indent}"
  189.                              omit-xml-declaration="{$omit-xml-declaration}"
  190.                              cdata-section-elements="{$cdata-section-elements}"
  191.                              doctype-system="{$doctype-system}"
  192.                              standalone="{$standalone}">
  193.                 <xsl:copy-of select="$content"/>
  194.               </exsl:document>
  195.             </xsl:when>
  196.             <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  197.               <exsl:document href="{$filename}"
  198.                              method="{$method}"
  199.                              encoding="{$encoding}"
  200.                              indent="{$indent}"
  201.                              omit-xml-declaration="{$omit-xml-declaration}"
  202.                              cdata-section-elements="{$cdata-section-elements}"
  203.                              standalone="{$standalone}">
  204.                 <xsl:copy-of select="$content"/>
  205.               </exsl:document>
  206.             </xsl:otherwise>
  207.           </xsl:choose>
  208.         </xsl:otherwise>
  209.       </xsl:choose>
  210.     </xsl:when>
  211.  
  212.     <xsl:when test="element-available('saxon:output')">
  213.       <xsl:choose>
  214.         <!-- Handle the permutations ... -->
  215.         <xsl:when test="$media-type != ''">
  216.           <xsl:choose>
  217.             <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  218.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  219.                             href="{$filename}"
  220.                             method="{$method}"
  221.                             encoding="{$encoding}"
  222.                             indent="{$indent}"
  223.                             omit-xml-declaration="{$omit-xml-declaration}"
  224.                             cdata-section-elements="{$cdata-section-elements}"
  225.                             media-type="{$media-type}"
  226.                             doctype-public="{$doctype-public}"
  227.                             doctype-system="{$doctype-system}"
  228.                             standalone="{$standalone}">
  229.                 <xsl:copy-of select="$content"/>
  230.               </saxon:output>
  231.             </xsl:when>
  232.             <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  233.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  234.                             href="{$filename}"
  235.                             method="{$method}"
  236.                             encoding="{$encoding}"
  237.                             indent="{$indent}"
  238.                             omit-xml-declaration="{$omit-xml-declaration}"
  239.                             cdata-section-elements="{$cdata-section-elements}"
  240.                             media-type="{$media-type}"
  241.                             doctype-public="{$doctype-public}"
  242.                             standalone="{$standalone}">
  243.                 <xsl:copy-of select="$content"/>
  244.               </saxon:output>
  245.             </xsl:when>
  246.             <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  247.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  248.                             href="{$filename}"
  249.                             method="{$method}"
  250.                             encoding="{$encoding}"
  251.                             indent="{$indent}"
  252.                             omit-xml-declaration="{$omit-xml-declaration}"
  253.                             cdata-section-elements="{$cdata-section-elements}"
  254.                             media-type="{$media-type}"
  255.                             doctype-system="{$doctype-system}"
  256.                             standalone="{$standalone}">
  257.                 <xsl:copy-of select="$content"/>
  258.               </saxon:output>
  259.             </xsl:when>
  260.             <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  261.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  262.                             href="{$filename}"
  263.                             method="{$method}"
  264.                             encoding="{$encoding}"
  265.                             indent="{$indent}"
  266.                             omit-xml-declaration="{$omit-xml-declaration}"
  267.                             cdata-section-elements="{$cdata-section-elements}"
  268.                             media-type="{$media-type}"
  269.                             standalone="{$standalone}">
  270.                 <xsl:copy-of select="$content"/>
  271.               </saxon:output>
  272.             </xsl:otherwise>
  273.           </xsl:choose>
  274.         </xsl:when>
  275.         <xsl:otherwise>
  276.           <xsl:choose>
  277.             <xsl:when test="$doctype-public != '' and $doctype-system != ''">
  278.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  279.                             href="{$filename}"
  280.                             method="{$method}"
  281.                             encoding="{$encoding}"
  282.                             indent="{$indent}"
  283.                             omit-xml-declaration="{$omit-xml-declaration}"
  284.                             cdata-section-elements="{$cdata-section-elements}"
  285.                             doctype-public="{$doctype-public}"
  286.                             doctype-system="{$doctype-system}"
  287.                             standalone="{$standalone}">
  288.                 <xsl:copy-of select="$content"/>
  289.               </saxon:output>
  290.             </xsl:when>
  291.             <xsl:when test="$doctype-public != '' and $doctype-system = ''">
  292.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  293.                             href="{$filename}"
  294.                             method="{$method}"
  295.                             encoding="{$encoding}"
  296.                             indent="{$indent}"
  297.                             omit-xml-declaration="{$omit-xml-declaration}"
  298.                             cdata-section-elements="{$cdata-section-elements}"
  299.                             doctype-public="{$doctype-public}"
  300.                             standalone="{$standalone}">
  301.                 <xsl:copy-of select="$content"/>
  302.               </saxon:output>
  303.             </xsl:when>
  304.             <xsl:when test="$doctype-public = '' and $doctype-system != ''">
  305.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  306.                             href="{$filename}"
  307.                             method="{$method}"
  308.                             encoding="{$encoding}"
  309.                             indent="{$indent}"
  310.                             omit-xml-declaration="{$omit-xml-declaration}"
  311.                             cdata-section-elements="{$cdata-section-elements}"
  312.                             doctype-system="{$doctype-system}"
  313.                             standalone="{$standalone}">
  314.                 <xsl:copy-of select="$content"/>
  315.               </saxon:output>
  316.             </xsl:when>
  317.             <xsl:otherwise><!-- $doctype-public = '' and $doctype-system = ''"> -->
  318.               <saxon:output saxon:character-representation="{$saxon.character.representation}"
  319.                             href="{$filename}"
  320.                             method="{$method}"
  321.                             encoding="{$encoding}"
  322.                             indent="{$indent}"
  323.                             omit-xml-declaration="{$omit-xml-declaration}"
  324.                             cdata-section-elements="{$cdata-section-elements}"
  325.                             standalone="{$standalone}">
  326.                 <xsl:copy-of select="$content"/>
  327.               </saxon:output>
  328.             </xsl:otherwise>
  329.           </xsl:choose>
  330.         </xsl:otherwise>
  331.       </xsl:choose>
  332.     </xsl:when>
  333.  
  334.     <xsl:when test="element-available('xalanredirect:write')">
  335.       <!-- Xalan uses xalanredirect -->
  336.       <xalanredirect:write file="{$filename}">
  337.         <xsl:copy-of select="$content"/>
  338.       </xalanredirect:write>
  339.     </xsl:when>
  340.  
  341.     <xsl:otherwise>
  342.       <!-- it doesn't matter since we won't be making chunks... -->
  343.       <xsl:message terminate="yes">
  344.         <xsl:text>Can't make chunks with </xsl:text>
  345.         <xsl:value-of select="system-property('xsl:vendor')"/>
  346.         <xsl:text>'s processor.</xsl:text>
  347.       </xsl:message>
  348.     </xsl:otherwise>
  349.   </xsl:choose>
  350. </xsl:template>
  351.  
  352. <xsl:template name="write.chunk.with.doctype">
  353.   <xsl:param name="filename" select="''"/>
  354.   <xsl:param name="quiet" select="0"/>
  355.  
  356.   <xsl:param name="method" select="$chunker.output.method"/>
  357.   <xsl:param name="encoding" select="$chunker.output.encoding"/>
  358.   <xsl:param name="indent" select="$chunker.output.indent"/>
  359.   <xsl:param name="omit-xml-declaration"
  360.              select="$chunker.output.omit-xml-declaration"/>
  361.   <xsl:param name="standalone" select="$chunker.output.standalone"/>
  362.   <xsl:param name="doctype-public" select="$chunker.output.doctype-public"/>
  363.   <xsl:param name="doctype-system" select="$chunker.output.doctype-system"/>
  364.   <xsl:param name="media-type" select="$chunker.output.media-type"/>
  365.   <xsl:param name="cdata-section-elements"
  366.              select="$chunker.output.cdata-section-elements"/>
  367.  
  368.   <xsl:param name="content"/>
  369.  
  370.   <xsl:call-template name="write.chunk">
  371.     <xsl:with-param name="filename" select="$filename"/>
  372.     <xsl:with-param name="quiet" select="$quiet"/>
  373.     <xsl:with-param name="method" select="$method"/>
  374.     <xsl:with-param name="encoding" select="$encoding"/>
  375.     <xsl:with-param name="indent" select="$indent"/>
  376.     <xsl:with-param name="omit-xml-declaration" select="$omit-xml-declaration"/>
  377.     <xsl:with-param name="standalone" select="$standalone"/>
  378.     <xsl:with-param name="doctype-public" select="$doctype-public"/>
  379.     <xsl:with-param name="doctype-system" select="$doctype-system"/>
  380.     <xsl:with-param name="media-type" select="$media-type"/>
  381.     <xsl:with-param name="cdata-section-elements" select="$cdata-section-elements"/>
  382.     <xsl:with-param name="content" select="$content"/>
  383.   </xsl:call-template>
  384. </xsl:template>
  385.  
  386. <xsl:template name="write.text.chunk">
  387.   <xsl:param name="filename" select="''"/>
  388.   <xsl:param name="quiet" select="0"/>
  389.   <xsl:param name="method" select="'text'"/>
  390.   <xsl:param name="encoding" select="$chunker.output.encoding"/>
  391.   <xsl:param name="media-type" select="$chunker.output.media-type"/>
  392.   <xsl:param name="content"/>
  393.  
  394.   <xsl:call-template name="write.chunk">
  395.     <xsl:with-param name="filename" select="$filename"/>
  396.     <xsl:with-param name="quiet" select="$quiet"/>
  397.     <xsl:with-param name="method" select="$method"/>
  398.     <xsl:with-param name="encoding" select="$encoding"/>
  399.     <xsl:with-param name="indent" select="'no'"/>
  400.     <xsl:with-param name="omit-xml-declaration" select="'no'"/>
  401.     <xsl:with-param name="standalone" select="'no'"/>
  402.     <xsl:with-param name="doctype-public"/>
  403.     <xsl:with-param name="doctype-system"/>
  404.     <xsl:with-param name="media-type" select="$media-type"/>
  405.     <xsl:with-param name="cdata-section-elements"/>
  406.     <xsl:with-param name="content" select="$content"/>
  407.   </xsl:call-template>
  408. </xsl:template>
  409.  
  410. </xsl:stylesheet>
  411.