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

  1. <?xml version="1.0" encoding="US-ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets. Do not edit this file.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:set="http://exslt.org/sets" exclude-result-prefixes="exsl set" version="1.0">
  5.  
  6. <!-- This module contains templates that match against HTML nodes. It is used
  7.      to post-process result tree fragments for some sorts of cleanup.
  8.      These templates can only ever be fired by a processor that supports
  9.      exslt:node-set(). -->
  10.  
  11. <!-- ==================================================================== -->
  12.  
  13. <!-- insert.html.p mode templates insert a particular RTF at the beginning
  14.      of the first paragraph in the primary RTF. -->
  15.  
  16. <xsl:template match="/" mode="insert.html.p">
  17.   <xsl:param name="mark" select="'?'"/>
  18.   <xsl:apply-templates mode="insert.html.p">
  19.     <xsl:with-param name="mark" select="$mark"/>
  20.   </xsl:apply-templates>
  21. </xsl:template>
  22.  
  23. <xsl:template match="*" mode="insert.html.p">
  24.   <xsl:param name="mark" select="'?'"/>
  25.   <xsl:copy>
  26.     <xsl:copy-of select="@*"/>
  27.     <xsl:apply-templates mode="insert.html.p">
  28.       <xsl:with-param name="mark" select="$mark"/>
  29.     </xsl:apply-templates>
  30.   </xsl:copy>
  31. </xsl:template>
  32.  
  33. <xsl:template match="p" mode="insert.html.p">
  34.   <xsl:param name="mark" select="'?'"/>
  35.   <xsl:copy>
  36.     <xsl:copy-of select="@*"/>
  37.     <xsl:if test="not(preceding::p)">
  38.       <xsl:copy-of select="$mark"/>
  39.     </xsl:if>
  40.     <xsl:apply-templates mode="insert.html.p">
  41.       <xsl:with-param name="mark" select="$mark"/>
  42.     </xsl:apply-templates>
  43.   </xsl:copy>
  44. </xsl:template>
  45.  
  46. <xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.p">
  47.   <xsl:param name="mark" select="'?'"/>
  48.   <xsl:copy/>
  49. </xsl:template>
  50.  
  51. <!-- ==================================================================== -->
  52.  
  53. <!-- insert.html.text mode templates insert a particular RTF at the beginning
  54.      of the first text-node in the primary RTF. -->
  55.  
  56. <xsl:template match="/" mode="insert.html.text">
  57.   <xsl:param name="mark" select="'?'"/>
  58.   <xsl:apply-templates mode="insert.html.text">
  59.     <xsl:with-param name="mark" select="$mark"/>
  60.   </xsl:apply-templates>
  61. </xsl:template>
  62.  
  63. <xsl:template match="*" mode="insert.html.text">
  64.   <xsl:param name="mark" select="'?'"/>
  65.   <xsl:copy>
  66.     <xsl:copy-of select="@*"/>
  67.     <xsl:apply-templates mode="insert.html.text">
  68.       <xsl:with-param name="mark" select="$mark"/>
  69.     </xsl:apply-templates>
  70.   </xsl:copy>
  71. </xsl:template>
  72.  
  73. <xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.text">
  74.   <xsl:param name="mark" select="'?'"/>
  75.  
  76.   <xsl:if test="not(preceding::text())">
  77.     <xsl:copy-of select="$mark"/>
  78.   </xsl:if>
  79.  
  80.   <xsl:copy/>
  81. </xsl:template>
  82.  
  83. <xsl:template match="processing-instruction()|comment()" mode="insert.html.text">
  84.   <xsl:param name="mark" select="'?'"/>
  85.   <xsl:copy/>
  86. </xsl:template>
  87.  
  88. <!-- ==================================================================== -->
  89.  
  90. <!-- unwrap.p mode templates remove blocks from HTML p elements (and
  91.      other places where blocks aren't allowed) -->
  92.  
  93. <xsl:template name="unwrap.p">
  94.   <xsl:param name="p"/>
  95.   <xsl:choose>
  96.     <xsl:when test="function-available('exsl:node-set')                     and function-available('set:leading')                     and function-available('set:trailing')">
  97.       <xsl:apply-templates select="exsl:node-set($p)" mode="unwrap.p"/>
  98.     </xsl:when>
  99.     <xsl:otherwise>
  100.       <xsl:copy-of select="$p"/>
  101.     </xsl:otherwise>
  102.   </xsl:choose>
  103. </xsl:template>
  104.  
  105. <xsl:template match="p" mode="unwrap.p">
  106.   <!-- xmlns:html is necessary for the xhtml stylesheet case -->
  107.   <xsl:variable xmlns:html="http://www.w3.org/1999/xhtml" name="blocks" select="address|blockquote|div|hr|h1|h2|h3|h4|h5|h6                         |layer|p|pre|table|dl|menu|ol|ul|form                         |html:address|html:blockquote|html:div|html:hr                         |html:h1|html:h2|html:h3|html:h4|html:h5|html:h6                         |html:layer|html:p|html:pre|html:table|html:dl                         |html:menu|html:ol|html:ul|html:form"/>
  108.   <xsl:choose>
  109.     <xsl:when test="$blocks">
  110.       <xsl:call-template name="unwrap.p.nodes">
  111.         <xsl:with-param name="wrap" select="."/>
  112.         <xsl:with-param name="first" select="1"/>
  113.         <xsl:with-param name="nodes" select="node()"/>
  114.         <xsl:with-param name="blocks" select="$blocks"/>
  115.       </xsl:call-template>
  116.     </xsl:when>
  117.     <xsl:otherwise>
  118.       <xsl:copy>
  119.         <xsl:copy-of select="@*"/>
  120.         <xsl:apply-templates mode="unwrap.p"/>
  121.       </xsl:copy>
  122.     </xsl:otherwise>
  123.   </xsl:choose>
  124. </xsl:template>
  125.  
  126. <xsl:template match="*" mode="unwrap.p">
  127.   <xsl:copy>
  128.     <xsl:copy-of select="@*"/>
  129.     <xsl:apply-templates mode="unwrap.p"/>
  130.   </xsl:copy>
  131. </xsl:template>
  132.  
  133. <xsl:template match="text()|processing-instruction()|comment()" mode="unwrap.p">
  134.   <xsl:copy/>
  135. </xsl:template>
  136.  
  137. <xsl:template name="unwrap.p.nodes">
  138.   <xsl:param name="wrap" select="."/>
  139.   <xsl:param name="first" select="0"/>
  140.   <xsl:param name="nodes"/>
  141.   <xsl:param name="blocks"/>
  142.   <xsl:variable name="block" select="$blocks[1]"/>
  143.  
  144.   <!-- This template should never get called if these functions aren't available -->
  145.   <!-- but this test is still necessary so that processors don't choke on the -->
  146.   <!-- function calls if they don't support the set: functions -->
  147.   <xsl:if test="function-available('set:leading')                 and function-available('set:trailing')">
  148.     <xsl:choose>
  149.       <xsl:when test="$blocks">
  150.         <xsl:variable name="leading" select="set:leading($nodes,$block)"/>
  151.         <xsl:variable name="trailing" select="set:trailing($nodes,$block)"/>
  152.  
  153.         <xsl:if test="($wrap/@id and $first = 1) or $leading">
  154.           <xsl:element name="{local-name($wrap)}" namespace="http://www.w3.org/1999/xhtml">
  155.             <xsl:for-each select="$wrap/@*">
  156.               <xsl:if test="$first != 0 or local-name(.) != 'id'">
  157.                 <xsl:copy/>
  158.               </xsl:if>
  159.             </xsl:for-each>
  160.             <xsl:apply-templates select="$leading" mode="unwrap.p"/>
  161.           </xsl:element>
  162.         </xsl:if>
  163.  
  164.         <xsl:apply-templates select="$block" mode="unwrap.p"/>
  165.  
  166.         <xsl:if test="$trailing">
  167.           <xsl:call-template name="unwrap.p.nodes">
  168.             <xsl:with-param name="wrap" select="$wrap"/>
  169.             <xsl:with-param name="nodes" select="$trailing"/>
  170.             <xsl:with-param name="blocks" select="$blocks[position() > 1]"/>
  171.           </xsl:call-template>
  172.         </xsl:if>
  173.       </xsl:when>
  174.  
  175.       <xsl:otherwise>
  176.         <xsl:if test="($wrap/@id and $first = 1) or $nodes">
  177.           <xsl:element name="{local-name($wrap)}" namespace="http://www.w3.org/1999/xhtml">
  178.             <xsl:for-each select="$wrap/@*">
  179.               <xsl:if test="$first != 0 or local-name(.) != 'id'">
  180.                 <xsl:copy/>
  181.               </xsl:if>
  182.             </xsl:for-each>
  183.             <xsl:apply-templates select="$nodes" mode="unwrap.p"/>
  184.           </xsl:element>
  185.         </xsl:if>
  186.       </xsl:otherwise>
  187.     </xsl:choose>
  188.   </xsl:if>
  189. </xsl:template>
  190.  
  191. <!-- ==================================================================== -->
  192. <!-- make.verbatim.mode replaces spaces and newlines -->
  193.  
  194. <xsl:template match="/" mode="make.verbatim.mode">
  195.   <xsl:apply-templates mode="make.verbatim.mode"/>
  196. </xsl:template>
  197.  
  198. <xsl:template match="*" mode="make.verbatim.mode">
  199.   <xsl:copy>
  200.     <xsl:copy-of select="@*"/>
  201.     <xsl:apply-templates mode="make.verbatim.mode"/>
  202.   </xsl:copy>
  203. </xsl:template>
  204.  
  205. <xsl:template match="processing-instruction()|comment()" mode="make.verbatim.mode">
  206.   <xsl:copy/>
  207. </xsl:template>
  208.  
  209. <xsl:template match="text()" mode="make.verbatim.mode">
  210.   <xsl:variable name="text" select="translate(., ' ', ' ')"/>
  211.  
  212.   <xsl:choose>
  213.     <xsl:when test="not(contains($text, ' '))">
  214.       <xsl:value-of select="$text"/>
  215.     </xsl:when>
  216.  
  217.     <xsl:otherwise>
  218.       <xsl:variable name="len" select="string-length($text)"/>
  219.  
  220.       <xsl:choose>
  221.         <xsl:when test="$len = 1">
  222.           <br xmlns="http://www.w3.org/1999/xhtml"/><xsl:text>
  223. </xsl:text>
  224.         </xsl:when>
  225.  
  226.         <xsl:otherwise>
  227.           <xsl:variable name="half" select="$len div 2"/>
  228.           <xsl:call-template name="make-verbatim-recursive">
  229.             <xsl:with-param name="text" select="substring($text, 1, $half)"/>
  230.           </xsl:call-template>
  231.           <xsl:call-template name="make-verbatim-recursive">
  232.             <xsl:with-param name="text" select="substring($text, ($half + 1), $len)"/>
  233.           </xsl:call-template>
  234.         </xsl:otherwise>
  235.       </xsl:choose>
  236.     </xsl:otherwise>
  237.   </xsl:choose>
  238. </xsl:template>
  239.  
  240. <xsl:template name="make-verbatim-recursive">
  241.   <xsl:param name="text" select="''"/>
  242.  
  243.   <xsl:choose>
  244.     <xsl:when test="not(contains($text, ' '))">
  245.       <xsl:value-of select="$text"/>
  246.     </xsl:when>
  247.  
  248.     <xsl:otherwise>
  249.       <xsl:variable name="len" select="string-length($text)"/>
  250.  
  251.       <xsl:choose>
  252.         <xsl:when test="$len = 1">
  253.           <br xmlns="http://www.w3.org/1999/xhtml"/><xsl:text>
  254. </xsl:text>
  255.         </xsl:when>
  256.  
  257.         <xsl:otherwise>
  258.           <xsl:variable name="half" select="$len div 2"/>
  259.           <xsl:call-template name="make-verbatim-recursive">
  260.             <xsl:with-param name="text" select="substring($text, 1, $half)"/>
  261.           </xsl:call-template>
  262.           <xsl:call-template name="make-verbatim-recursive">
  263.             <xsl:with-param name="text" select="substring($text, ($half + 1), $len)"/>
  264.           </xsl:call-template>
  265.         </xsl:otherwise>
  266.       </xsl:choose>
  267.     </xsl:otherwise>
  268.   </xsl:choose>
  269. </xsl:template>
  270.  
  271. <!-- ==================================================================== -->
  272.  
  273. </xsl:stylesheet>
  274.