home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 Autumn / INTERNET109.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _776565283AEC4589870AD288805FF6BD < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-04  |  7.3 KB  |  231 lines

  1. <?xml version='1.0'?>
  2. <!-- vim:set sts=2 shiftwidth=2 syntax=sgml: -->
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.                 version='1.0'>
  5.  
  6. <xsl:template match="synopfragment">
  7. <xsl:text> .PP </xsl:text>
  8. <xsl:apply-templates/>
  9. </xsl:template>
  10. <!--
  11.   there's a bug were an <arg> that's not inside a <group> isn't made bold
  12. -->
  13.  
  14. <xsl:template match="group|arg">
  15.   <xsl:variable name="choice" select="@choice"/>
  16.   <xsl:variable name="rep" select="@rep"/>
  17.   <xsl:variable name="sepchar">
  18.     <xsl:choose>
  19.       <xsl:when test="ancestor-or-self::*/@sepchar">
  20.         <xsl:value-of select="ancestor-or-self::*/@sepchar"/>
  21.       </xsl:when>
  22.       <xsl:otherwise>
  23.         <xsl:text> </xsl:text>
  24.       </xsl:otherwise>
  25.     </xsl:choose>
  26.   </xsl:variable>
  27.   <xsl:if test="position()>1"><xsl:value-of select="$sepchar"/></xsl:if>
  28.   <xsl:choose>
  29.     <xsl:when test="$choice='plain'">
  30.       <!-- do nothing -->
  31.     </xsl:when>
  32.     <xsl:when test="$choice='req'">
  33.       <xsl:value-of select="$arg.choice.req.open.str"/>
  34.     </xsl:when>
  35.     <xsl:when test="$choice='opt'">
  36.       <xsl:value-of select="$arg.choice.opt.open.str"/>
  37.     </xsl:when>
  38.     <xsl:otherwise>
  39.       <xsl:value-of select="$arg.choice.def.open.str"/>
  40.     </xsl:otherwise>
  41.   </xsl:choose>
  42.   <xsl:variable name="arg">
  43.     <xsl:apply-templates/>
  44.   </xsl:variable>
  45.   <xsl:value-of select="normalize-space($arg)"/>
  46.   <xsl:choose>
  47.     <xsl:when test="$rep='repeat'">
  48.       <xsl:value-of select="$arg.rep.repeat.str"/>
  49.     </xsl:when>
  50.     <xsl:when test="$rep='norepeat'">
  51.       <xsl:value-of select="$arg.rep.norepeat.str"/>
  52.     </xsl:when>
  53.     <xsl:otherwise>
  54.       <xsl:value-of select="$arg.rep.def.str"/>
  55.     </xsl:otherwise>
  56.   </xsl:choose>
  57.   <xsl:choose>
  58.     <xsl:when test="$choice='plain'">
  59.       <xsl:if test='arg'>
  60.       <xsl:value-of select="$arg.choice.plain.close.str"/>
  61.       </xsl:if>
  62.     </xsl:when>
  63.     <xsl:when test="$choice='req'">
  64.       <xsl:value-of select="$arg.choice.req.close.str"/>
  65.     </xsl:when>
  66.     <xsl:when test="$choice='opt'">
  67.       <xsl:value-of select="$arg.choice.opt.close.str"/>
  68.     </xsl:when>
  69.     <xsl:otherwise>
  70.       <xsl:value-of select="$arg.choice.def.close.str"/>
  71.     </xsl:otherwise>
  72.   </xsl:choose>
  73. </xsl:template>
  74.  
  75. <xsl:template match="group/arg">
  76.   <xsl:if test="position()>1">
  77.     <xsl:value-of select="$arg.or.sep"/>
  78.   </xsl:if>
  79.   <!-- Don't use the 'bold' named template here since there may be -->
  80.   <!-- child elements that require different markup (such as       -->
  81.   <!-- <replaceable>).                                             -->
  82.   <xsl:text>\fB</xsl:text>
  83.   <xsl:apply-templates/>
  84.   <xsl:text>\fR</xsl:text>
  85. </xsl:template>
  86.  
  87. <xsl:template match="command">
  88.   <xsl:apply-templates mode="bold" select="."/>
  89. </xsl:template>
  90.  
  91. <xsl:template match="function[not(ancestor::command)]">
  92.   <xsl:apply-templates mode="bold" select="."/>
  93. </xsl:template>
  94.  
  95. <xsl:template match="parameter[not(ancestor::command)]">
  96.   <xsl:apply-templates mode="italic" select="."/>
  97. </xsl:template>
  98.  
  99. <xsl:template match="sbr">
  100.   <xsl:variable name="cmd" select="ancestor::cmdsynopsis/command"/>
  101.   <xsl:text> </xsl:text>
  102.   <xsl:value-of select="translate($cmd,$cmd,'                        ')"/>
  103. </xsl:template>
  104.  
  105. <xsl:template name="wrap-cmd">
  106.   <xsl:param name="indent" select="''"/>
  107.   <xsl:param name="text" select="''"/>
  108.   <xsl:param name="allow" select="75"/>
  109.   <xsl:param name="width" select="$allow - string-length($indent)"/>
  110.   <xsl:variable name="total" select="string-length($text)"/>
  111.   <xsl:variable name="split"
  112.                 select="substring($text,$width+1,$total - $width)"/>
  113.   <xsl:variable name="fragment" select="substring-before($split,' ')"/>
  114.   <xsl:variable name="line">
  115.     <xsl:value-of select="substring($text,1,$width)"/>
  116.     <xsl:choose>
  117.       <xsl:when test="$fragment!=''">
  118.         <xsl:value-of select="$fragment"/>
  119.       </xsl:when>
  120.       <xsl:otherwise>
  121.         <xsl:value-of select="$split"/>
  122.       </xsl:otherwise>
  123.     </xsl:choose>
  124.   </xsl:variable>
  125.   <xsl:choose>
  126.     <xsl:when test="$split=''">
  127.       <xsl:value-of select="$line"/>
  128.     </xsl:when>
  129.     <xsl:otherwise>
  130.       <xsl:value-of select="$line"/>
  131.       <xsl:text> </xsl:text>
  132.       <xsl:value-of select="$indent"/>
  133.       <xsl:variable name="done" select="string-length($line)"/>
  134.       <xsl:variable name="remaining" select="$total - $done + 1"/>
  135.       <xsl:call-template name="wrap-cmd">
  136.         <xsl:with-param name="indent" select="$indent"/>
  137.         <xsl:with-param name="text"
  138.                         select="substring($text,1+$done,$remaining)"/>
  139.       </xsl:call-template>
  140.     </xsl:otherwise>
  141.   </xsl:choose>
  142. </xsl:template>
  143.  
  144. <xsl:template match="cmdsynopsis">
  145.   <xsl:text> .nf </xsl:text>
  146.   <xsl:choose>
  147.     <xsl:when test=".//sbr">
  148.       <!-- The author has put explicit formatting hints in for us. -->
  149.       <xsl:apply-templates/>
  150.     </xsl:when>
  151.     <xsl:otherwise>
  152.       <!-- Try to do some smart formatting. -->
  153.       <xsl:variable name="cmdsynopsis">
  154.         <xsl:apply-templates/>
  155.       </xsl:variable>
  156.       <xsl:variable name="cmd" select="command"/>
  157.       <xsl:variable name="indent"
  158.                     select="translate($cmd,$cmd,'                         ')"/>
  159.       <xsl:text>\fB</xsl:text>
  160.       <xsl:value-of select="$cmd"/><xsl:text>\fR </xsl:text>
  161.       <xsl:call-template name="wrap-cmd">
  162.         <xsl:with-param name="indent" select="$indent"/>
  163.         <xsl:with-param name="text" select="substring-after($cmdsynopsis,' ')"/>
  164.       </xsl:call-template>
  165.     </xsl:otherwise>
  166.   </xsl:choose>
  167.   <xsl:text> .fi </xsl:text>
  168. </xsl:template>
  169.  
  170. <xsl:template match="synopsis">
  171.   <xsl:text> .nf </xsl:text>
  172.   <xsl:apply-templates/>
  173.   <xsl:text> .fi </xsl:text>
  174. </xsl:template>
  175.  
  176. <xsl:template match="void">
  177.   <xsl:text> (void</xsl:text>
  178. </xsl:template>
  179.  
  180. <xsl:template match="varargs">
  181.   <xsl:text> (...</xsl:text>
  182. </xsl:template>
  183.  
  184. <xsl:template match="funcsynopsisinfo">
  185.   <xsl:text> </xsl:text>
  186.   <xsl:apply-templates/>
  187.   <xsl:text> .sp </xsl:text>
  188. </xsl:template>
  189.  
  190. <xsl:template match="funcsynopsis">
  191.   <xsl:text>.nf </xsl:text>
  192.   <xsl:apply-templates/>
  193.   <xsl:text>.fi </xsl:text>
  194. </xsl:template>
  195.  
  196. <!-- TODO: Handle K&R-style parameter lists
  197.            Comment that used to go with the paramdef template, which
  198.        is now obsolete and thus deleted
  199. -->
  200.  
  201. <xsl:template match="funcprototype">
  202.   <xsl:variable name="funcprototype">
  203.     <xsl:apply-templates select="funcdef"/>
  204.   </xsl:variable>
  205.   <xsl:text>.sp </xsl:text>
  206.   <xsl:value-of select="normalize-space ($funcprototype)"/>
  207.   <xsl:text> (</xsl:text>
  208.   <xsl:for-each select="paramdef">
  209.     <xsl:variable name="param">
  210.       <xsl:apply-templates select="." />
  211.     </xsl:variable>
  212.     <xsl:value-of select="normalize-space ($param)" />
  213.     <xsl:choose>
  214.       <xsl:when test="following-sibling::paramdef">
  215.     <xsl:text>, </xsl:text>
  216.       </xsl:when>
  217.       <xsl:otherwise>
  218.     <xsl:text>); .RE </xsl:text>
  219.       </xsl:otherwise>
  220.     </xsl:choose>
  221.     <xsl:if test="not (preceding-sibling::paramdef)">
  222.       <xsl:text>.RS </xsl:text>
  223.       <xsl:value-of
  224.     select="string-length(normalize-space ($funcprototype)) - 4" />
  225.       <xsl:text> </xsl:text>
  226.     </xsl:if>
  227.   </xsl:for-each>
  228. </xsl:template>
  229.  
  230. </xsl:stylesheet>
  231.