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

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  4.                 exclude-result-prefixes="doc"
  5.                 version="1.0">
  6.  
  7. <xsl:template name="blank.spans">
  8.   <xsl:param name="cols" select="1"/>
  9.   <xsl:if test="$cols > 0">
  10.     <xsl:text>0:</xsl:text>
  11.     <xsl:call-template name="blank.spans">
  12.       <xsl:with-param name="cols" select="$cols - 1"/>
  13.     </xsl:call-template>
  14.   </xsl:if>
  15. </xsl:template>
  16.  
  17. <xsl:template name="calculate.following.spans">
  18.   <xsl:param name="colspan" select="1"/>
  19.   <xsl:param name="spans" select="''"/>
  20.  
  21.   <xsl:choose>
  22.     <xsl:when test="$colspan > 0">
  23.       <xsl:call-template name="calculate.following.spans">
  24.         <xsl:with-param name="colspan" select="$colspan - 1"/>
  25.         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
  26.       </xsl:call-template>
  27.     </xsl:when>
  28.     <xsl:otherwise>
  29.       <xsl:value-of select="$spans"/>
  30.     </xsl:otherwise>
  31.   </xsl:choose>
  32. </xsl:template>
  33.  
  34. <xsl:template name="finaltd">
  35.   <xsl:param name="spans"/>
  36.   <xsl:param name="col" select="0"/>
  37.  
  38.   <xsl:if test="$spans != ''">
  39.     <xsl:choose>
  40.       <xsl:when test="starts-with($spans,'0:')">
  41.         <xsl:call-template name="empty.table.cell">
  42.           <xsl:with-param name="colnum" select="$col"/>
  43.         </xsl:call-template>
  44.       </xsl:when>
  45.       <xsl:otherwise></xsl:otherwise>
  46.     </xsl:choose>
  47.  
  48.     <xsl:call-template name="finaltd">
  49.       <xsl:with-param name="spans" select="substring-after($spans,':')"/>
  50.       <xsl:with-param name="col" select="$col+1"/>
  51.     </xsl:call-template>
  52.   </xsl:if>
  53. </xsl:template>
  54.  
  55. <xsl:template name="sfinaltd">
  56.   <xsl:param name="spans"/>
  57.  
  58.   <xsl:if test="$spans != ''">
  59.     <xsl:choose>
  60.       <xsl:when test="starts-with($spans,'0:')">0:</xsl:when>
  61.       <xsl:otherwise>
  62.         <xsl:value-of select="substring-before($spans,':')-1"/>
  63.         <xsl:text>:</xsl:text>
  64.       </xsl:otherwise>
  65.     </xsl:choose>
  66.  
  67.     <xsl:call-template name="sfinaltd">
  68.       <xsl:with-param name="spans" select="substring-after($spans,':')"/>
  69.     </xsl:call-template>
  70.   </xsl:if>
  71. </xsl:template>
  72.  
  73. <xsl:template name="entry.colnum">
  74.   <xsl:param name="entry" select="."/>
  75.  
  76.   <xsl:choose>
  77.     <xsl:when test="$entry/@spanname">
  78.       <xsl:variable name="spanname" select="$entry/@spanname"/>
  79.       <xsl:variable name="spanspec"
  80.                     select="$entry/ancestor::tgroup/spanspec[@spanname=$spanname]"/>
  81.       <xsl:variable name="colspec"
  82.                     select="$entry/ancestor::tgroup/colspec[@colname=$spanspec/@namest]"/>
  83.       <xsl:call-template name="colspec.colnum">
  84.         <xsl:with-param name="colspec" select="$colspec"/>
  85.       </xsl:call-template>
  86.     </xsl:when>
  87.     <xsl:when test="$entry/@colname">
  88.       <xsl:variable name="colname" select="$entry/@colname"/>
  89.       <xsl:variable name="colspec"
  90.                     select="$entry/ancestor::tgroup/colspec[@colname=$colname]"/>
  91.       <xsl:call-template name="colspec.colnum">
  92.         <xsl:with-param name="colspec" select="$colspec"/>
  93.       </xsl:call-template>
  94.     </xsl:when>
  95.     <xsl:when test="$entry/@namest">
  96.       <xsl:variable name="namest" select="$entry/@namest"/>
  97.       <xsl:variable name="colspec"
  98.                     select="$entry/ancestor::tgroup/colspec[@colname=$namest]"/>
  99.       <xsl:call-template name="colspec.colnum">
  100.         <xsl:with-param name="colspec" select="$colspec"/>
  101.       </xsl:call-template>
  102.     </xsl:when>
  103.     <!-- no idea, return 0 -->
  104.     <xsl:otherwise>0</xsl:otherwise>
  105.   </xsl:choose>
  106. </xsl:template>
  107.  
  108. <doc:template name="entry.colnum" xmlns="">
  109. <refpurpose>Determine the column number in which a given entry occurs</refpurpose>
  110. <refdescription>
  111. <para>If an <sgmltag>entry</sgmltag> has a
  112. <sgmltag class="attribute">colname</sgmltag> or
  113. <sgmltag class="attribute">namest</sgmltag> attribute, this template
  114. will determine the number of the column in which the entry should occur.
  115. For other <sgmltag>entry</sgmltag>s, nothing is returned.</para>
  116. </refdescription>
  117. <refparameter>
  118. <variablelist>
  119. <varlistentry><term>entry</term>
  120. <listitem>
  121. <para>The <sgmltag>entry</sgmltag>-element which is to be tested.</para>
  122. </listitem>
  123. </varlistentry>
  124. </variablelist>
  125. </refparameter>
  126.  
  127. <refreturn>
  128. <para>This template returns the column number if it can be determined,
  129. or 0 (the empty string)</para>
  130. </refreturn>
  131. </doc:template>
  132.  
  133. <xsl:template name="colspec.colnum">
  134.   <xsl:param name="colspec" select="."/>
  135.   <xsl:choose>
  136.     <xsl:when test="$colspec/@colnum">
  137.       <xsl:value-of select="$colspec/@colnum"/>
  138.     </xsl:when>
  139.     <xsl:when test="$colspec/preceding-sibling::colspec">
  140.       <xsl:variable name="prec.colspec.colnum">
  141.         <xsl:call-template name="colspec.colnum">
  142.           <xsl:with-param name="colspec"
  143.                           select="$colspec/preceding-sibling::colspec[1]"/>
  144.         </xsl:call-template>
  145.       </xsl:variable>
  146.       <xsl:value-of select="$prec.colspec.colnum + 1"/>
  147.     </xsl:when>
  148.     <xsl:otherwise>1</xsl:otherwise>
  149.   </xsl:choose>
  150. </xsl:template>
  151.  
  152. <xsl:template name="calculate.colspan">
  153.   <xsl:param name="entry" select="."/>
  154.   <xsl:variable name="spanname" select="$entry/@spanname"/>
  155.   <xsl:variable name="spanspec"
  156.                 select="$entry/ancestor::tgroup/spanspec[@spanname=$spanname]"/>
  157.  
  158.   <xsl:variable name="namest">
  159.     <xsl:choose>
  160.       <xsl:when test="@spanname">
  161.         <xsl:value-of select="$spanspec/@namest"/>
  162.       </xsl:when>
  163.       <xsl:otherwise>
  164.         <xsl:value-of select="$entry/@namest"/>
  165.       </xsl:otherwise>
  166.     </xsl:choose>
  167.   </xsl:variable>
  168.  
  169.   <xsl:variable name="nameend">
  170.     <xsl:choose>
  171.       <xsl:when test="@spanname">
  172.         <xsl:value-of select="$spanspec/@nameend"/>
  173.       </xsl:when>
  174.       <xsl:otherwise>
  175.         <xsl:value-of select="$entry/@nameend"/>
  176.       </xsl:otherwise>
  177.     </xsl:choose>
  178.   </xsl:variable>
  179.  
  180.   <xsl:variable name="scol">
  181.     <xsl:call-template name="colspec.colnum">
  182.       <xsl:with-param name="colspec"
  183.                       select="$entry/ancestor::tgroup/colspec[@colname=$namest]"/>
  184.     </xsl:call-template>
  185.   </xsl:variable>
  186.  
  187.   <xsl:variable name="ecol">
  188.     <xsl:call-template name="colspec.colnum">
  189.       <xsl:with-param name="colspec"
  190.                       select="$entry/ancestor::tgroup/colspec[@colname=$nameend]"/>
  191.     </xsl:call-template>
  192.   </xsl:variable>
  193.  
  194.   <xsl:choose>
  195.     <xsl:when test="$namest != '' and $nameend != ''">
  196.       <xsl:choose>
  197.         <xsl:when test="$ecol >= $scol">
  198.           <xsl:value-of select="$ecol - $scol + 1"/>
  199.         </xsl:when>
  200.         <xsl:otherwise>
  201.           <xsl:value-of select="$scol - $ecol + 1"/>
  202.         </xsl:otherwise>
  203.       </xsl:choose>
  204.     </xsl:when>
  205.     <xsl:otherwise>1</xsl:otherwise>
  206.   </xsl:choose>
  207. </xsl:template>
  208.  
  209. <xsl:template name="calculate.rowsep">
  210.   <xsl:param name="entry" select="."/>
  211.   <xsl:param name="colnum" select="0"/>
  212.  
  213.   <xsl:call-template name="inherited.table.attribute">
  214.     <xsl:with-param name="entry" select="$entry"/>
  215.     <xsl:with-param name="colnum" select="$colnum"/>
  216.     <xsl:with-param name="attribute" select="'rowsep'"/>
  217.   </xsl:call-template>
  218. </xsl:template>
  219.  
  220. <xsl:template name="calculate.colsep">
  221.   <xsl:param name="entry" select="."/>
  222.   <xsl:param name="colnum" select="0"/>
  223.  
  224.   <xsl:call-template name="inherited.table.attribute">
  225.     <xsl:with-param name="entry" select="$entry"/>
  226.     <xsl:with-param name="colnum" select="$colnum"/>
  227.     <xsl:with-param name="attribute" select="'colsep'"/>
  228.   </xsl:call-template>
  229. </xsl:template>
  230.  
  231. <xsl:template name="inherited.table.attribute">
  232.   <xsl:param name="entry" select="."/>
  233.   <xsl:param name="row" select="$entry/ancestor-or-self::row[1]"/>
  234.   <xsl:param name="colnum" select="0"/>
  235.   <xsl:param name="attribute" select="'colsep'"/>
  236.  
  237.   <xsl:variable name="tgroup" select="$row/ancestor::tgroup[1]"/>
  238.  
  239.   <xsl:variable name="entry.value">
  240.     <xsl:call-template name="get-attribute">
  241.       <xsl:with-param name="element" select="$entry"/>
  242.       <xsl:with-param name="attribute" select="$attribute"/>
  243.     </xsl:call-template>
  244.   </xsl:variable>
  245.  
  246.   <xsl:variable name="row.value">
  247.     <xsl:call-template name="get-attribute">
  248.       <xsl:with-param name="element" select="$row"/>
  249.       <xsl:with-param name="attribute" select="$attribute"/>
  250.     </xsl:call-template>
  251.   </xsl:variable>
  252.  
  253.   <xsl:variable name="span.value">
  254.     <xsl:if test="$entry/@spanname">
  255.       <xsl:variable name="spanname" select="$entry/@spanname"/>
  256.       <xsl:variable name="spanspec"
  257.                     select="$tgroup/spanspec[@spanname=$spanname]"/>
  258.       <xsl:variable name="span.colspec"
  259.                     select="$tgroup/colspec[@colname=$spanspec/@namest]"/>
  260.  
  261.       <xsl:variable name="spanspec.value">
  262.         <xsl:call-template name="get-attribute">
  263.           <xsl:with-param name="element" select="$spanspec"/>
  264.           <xsl:with-param name="attribute" select="$attribute"/>
  265.         </xsl:call-template>
  266.       </xsl:variable>
  267.  
  268.       <xsl:variable name="scolspec.value">
  269.         <xsl:call-template name="get-attribute">
  270.           <xsl:with-param name="element" select="$span.colspec"/>
  271.           <xsl:with-param name="attribute" select="$attribute"/>
  272.         </xsl:call-template>
  273.       </xsl:variable>
  274.  
  275.       <xsl:choose>
  276.         <xsl:when test="$spanspec.value != ''">
  277.           <xsl:value-of select="$spanspec.value"/>
  278.         </xsl:when>
  279.         <xsl:when test="$scolspec.value != ''">
  280.           <xsl:value-of select="$scolspec.value"/>
  281.         </xsl:when>
  282.         <xsl:otherwise></xsl:otherwise>
  283.       </xsl:choose>
  284.     </xsl:if>
  285.   </xsl:variable>
  286.  
  287.   <xsl:variable name="namest.value">
  288.     <xsl:if test="$entry/@namest">
  289.       <xsl:variable name="namest" select="$entry/@namest"/>
  290.       <xsl:variable name="colspec"
  291.                     select="$tgroup/colspec[@colname=$namest]"/>
  292.  
  293.       <xsl:variable name="namest.value">
  294.         <xsl:call-template name="get-attribute">
  295.           <xsl:with-param name="element" select="$colspec"/>
  296.           <xsl:with-param name="attribute" select="$attribute"/>
  297.         </xsl:call-template>
  298.       </xsl:variable>
  299.  
  300.       <xsl:choose>
  301.         <xsl:when test="$namest.value">
  302.           <xsl:value-of select="$namest.value"/>
  303.         </xsl:when>
  304.         <xsl:otherwise></xsl:otherwise>
  305.       </xsl:choose>
  306.     </xsl:if>
  307.   </xsl:variable>
  308.  
  309.   <xsl:variable name="tgroup.value">
  310.     <xsl:call-template name="get-attribute">
  311.       <xsl:with-param name="element" select="$tgroup"/>
  312.       <xsl:with-param name="attribute" select="$attribute"/>
  313.     </xsl:call-template>
  314.   </xsl:variable>
  315.  
  316.   <xsl:variable name="default.value">
  317.     <!-- rowsep and colsep have defaults based ultimately on the frame setting -->
  318.     <!-- handle those here, for everything else, the default is the tgroup value -->
  319.     <xsl:choose>
  320.       <xsl:when test="$tgroup.value != ''">
  321.         <xsl:value-of select="$tgroup.value"/>
  322.       </xsl:when>
  323.       <xsl:when test="$attribute = 'rowsep'">
  324.         <xsl:if test="$tgroup/parent::*/@frame = 'all'">
  325.           <xsl:value-of select="1"/>
  326.         </xsl:if>
  327.       </xsl:when>
  328.       <xsl:when test="$attribute = 'colsep'">
  329.         <xsl:if test="$tgroup/parent::*/@frame = 'all'">
  330.           <xsl:value-of select="1"/>
  331.         </xsl:if>
  332.       </xsl:when>
  333.       <xsl:otherwise><!-- empty --></xsl:otherwise>
  334.     </xsl:choose>
  335.   </xsl:variable>
  336.  
  337.   <xsl:choose>
  338.     <xsl:when test="$entry.value != ''">
  339.       <xsl:value-of select="$entry.value"/>
  340.     </xsl:when>
  341.     <xsl:when test="$row.value != ''">
  342.       <xsl:value-of select="$row.value"/>
  343.     </xsl:when>
  344.     <xsl:when test="$span.value != ''">
  345.       <xsl:value-of select="$span.value"/>
  346.     </xsl:when>
  347.     <xsl:when test="$namest.value != ''">
  348.       <xsl:value-of select="$namest.value"/>
  349.     </xsl:when>
  350.     <xsl:when test="$colnum > 0">
  351.       <xsl:variable name="calc.colvalue">
  352.         <xsl:call-template name="colnum.colspec">
  353.           <xsl:with-param name="colnum" select="$colnum"/>
  354.           <xsl:with-param name="attribute" select="$attribute"/>
  355.         </xsl:call-template>
  356.       </xsl:variable>
  357.       <xsl:choose>
  358.         <xsl:when test="$calc.colvalue != ''">
  359.           <xsl:value-of select="$calc.colvalue"/>
  360.         </xsl:when>
  361.         <xsl:otherwise>
  362.           <xsl:value-of select="$default.value"/>
  363.         </xsl:otherwise>
  364.       </xsl:choose>
  365.     </xsl:when>
  366.     <xsl:otherwise>
  367.       <xsl:value-of select="$default.value"/>
  368.     </xsl:otherwise>
  369.   </xsl:choose>
  370. </xsl:template>
  371.  
  372. <xsl:template name="colnum.colspec">
  373.   <xsl:param name="colnum" select="0"/>
  374.   <xsl:param name="attribute" select="'colname'"/>
  375.   <xsl:param name="colspecs" select="ancestor::tgroup/colspec"/>
  376.   <xsl:param name="count" select="1"/>
  377.  
  378.   <xsl:choose>
  379.     <xsl:when test="not($colspecs) or $count > $colnum">
  380.       <!-- nop -->
  381.     </xsl:when>
  382.     <xsl:when test="$colspecs[1]/@colnum">
  383.       <xsl:choose>
  384.         <xsl:when test="$colspecs[1]/@colnum = $colnum">
  385.           <xsl:call-template name="get-attribute">
  386.             <xsl:with-param name="element" select="$colspecs[1]"/>
  387.             <xsl:with-param name="attribute" select="$attribute"/>
  388.           </xsl:call-template>
  389.         </xsl:when>
  390.         <xsl:otherwise>
  391.           <xsl:call-template name="colnum.colspec">
  392.             <xsl:with-param name="colnum" select="$colnum"/>
  393.             <xsl:with-param name="attribute" select="$attribute"/>
  394.             <xsl:with-param name="colspecs"
  395.                             select="$colspecs[position()>1]"/>
  396.             <xsl:with-param name="count"
  397.                             select="$colspecs[1]/@colnum+1"/>
  398.           </xsl:call-template>
  399.         </xsl:otherwise>
  400.       </xsl:choose>
  401.     </xsl:when>
  402.     <xsl:otherwise>
  403.       <xsl:choose>
  404.         <xsl:when test="$count = $colnum">
  405.           <xsl:call-template name="get-attribute">
  406.             <xsl:with-param name="element" select="$colspecs[1]"/>
  407.             <xsl:with-param name="attribute" select="$attribute"/>
  408.           </xsl:call-template>
  409.         </xsl:when>
  410.         <xsl:otherwise>
  411.           <xsl:call-template name="colnum.colspec">
  412.             <xsl:with-param name="colnum" select="$colnum"/>
  413.             <xsl:with-param name="attribute" select="$attribute"/>
  414.             <xsl:with-param name="colspecs"
  415.                             select="$colspecs[position()>1]"/>
  416.             <xsl:with-param name="count" select="$count+1"/>
  417.           </xsl:call-template>
  418.         </xsl:otherwise>
  419.       </xsl:choose>
  420.     </xsl:otherwise>
  421.   </xsl:choose>
  422. </xsl:template>
  423.  
  424. <xsl:template name="get-attribute">
  425.   <xsl:param name="element" select="."/>
  426.   <xsl:param name="attribute" select="''"/>
  427.  
  428.   <xsl:for-each select="$element/@*">
  429.     <xsl:if test="local-name(.) = $attribute">
  430.       <xsl:value-of select="."/>
  431.     </xsl:if>
  432.   </xsl:for-each>
  433. </xsl:template>
  434.  
  435. </xsl:stylesheet>
  436.