home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 2 / MF_UK_160_2.iso / pc / DiscContent / Trials / oxygen / samples / fo / macro.xsl
Encoding:
Extensible Markup Language  |  2005-07-21  |  72.8 KB  |  2,089 lines

  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2.  
  3. <!-- Example from: http://www.renderx.net
  4.     Copyright © 2004 RenderX, Inc.-->
  5.     
  6. <!DOCTYPE xsl:stylesheet [
  7. <!ENTITY DECLARE-MACRO-PARAMETERS "<xsl:param name='arg'/><xsl:param name='arg1'/><xsl:param name='arg2'/><xsl:param name='arg3'/><xsl:param name='arg4'/><xsl:param name='arg5'/><xsl:param name='arg6'/><xsl:param name='arg7'/><xsl:param name='arg8'/><xsl:param name='arg9'/><xsl:param name='argA'/><xsl:param name='argB'/><xsl:param name='argC'/><xsl:param name='argD'/><xsl:param name='counter' select='1'/><xsl:param name='test-number' select='1'/><xsl:param name='subtest-number' select='1'/>">
  8. <!ENTITY WITH-MACRO-PARAMETERS-NO-COUNTER-AND-TEST-NUMBER "<xsl:with-param name='arg' select='$arg'/><xsl:with-param name='arg1' select='$arg1'/><xsl:with-param name='arg2' select='$arg2'/><xsl:with-param name='arg3' select='$arg3'/><xsl:with-param name='arg4' select='$arg4'/><xsl:with-param name='arg5' select='$arg5'/><xsl:with-param name='arg6' select='$arg6'/><xsl:with-param name='arg7' select='$arg7'/><xsl:with-param name='arg8' select='$arg8'/><xsl:with-param name='arg9' select='$arg9'/><xsl:with-param name='argA' select='$argA'/><xsl:with-param name='argB' select='$argB'/><xsl:with-param name='argC' select='$argC'/><xsl:with-param name='argD' select='$argD'/>">
  9.  
  10. <!ENTITY WITH-MACRO-PARAMETERS-NO-COUNTER "&WITH-MACRO-PARAMETERS-NO-COUNTER-AND-TEST-NUMBER;<xsl:with-param name='test-number' select='$test-number'/><xsl:with-param name='subtest-number' select='$subtest-number'/>">
  11.  
  12. <!ENTITY WITH-MACRO-PARAMETERS-NO-TEST-NUMBER "&WITH-MACRO-PARAMETERS-NO-COUNTER-AND-TEST-NUMBER;<xsl:with-param name='counter' select='$counter'/>">
  13.  
  14. <!ENTITY WITH-MACRO-PARAMETERS-NO-SUBTEST-NUMBER "&WITH-MACRO-PARAMETERS-NO-TEST-NUMBER;<xsl:with-param name='test-number' select='$test-number'/>">
  15.  
  16. <!ENTITY WITH-MACRO-PARAMETERS "&WITH-MACRO-PARAMETERS-NO-COUNTER;<xsl:with-param name='counter' select='$counter'/>">
  17. ]>
  18.  
  19. <xsl:stylesheet version="1.0"
  20.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  21.                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
  22.                 xmlns:rx="http://www.renderx.com/XSL/Extensions"
  23.                 xmlns:xep="http://www.renderx.com/XEP/xep"
  24.  
  25.                 xmlns:svg="http://www.w3.org/2000/svg"
  26.                 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  27.  
  28.                 exclude-result-prefixes="rx svg">
  29.  
  30. <xsl:output method="xml"
  31.             version="1.0"
  32.             indent="yes"
  33.             encoding="ISO-8859-1"/>
  34.  
  35. <xsl:param name="image-path">Images/</xsl:param>
  36. <xsl:param name="level">1,2</xsl:param>   <!-- 1=base, 2=main, 3=fallback, 4=all, d=(main-base) -->
  37.  
  38. <xsl:variable name="dlevel">
  39.   <xsl:call-template name="trans-level">
  40.     <xsl:with-param name="rowval"><xsl:value-of select="normalize-space($level)"/></xsl:with-param>
  41.   </xsl:call-template>
  42. </xsl:variable>
  43.  
  44. <xsl:template name="trans-level">
  45.   <xsl:param name="rowval"/>
  46.   <xsl:choose>
  47.     <xsl:when test="contains($rowval,'base')">
  48.       <xsl:call-template name="trans-level">
  49.         <xsl:with-param name="rowval"><xsl:value-of select="concat(substring-before($rowval,'base'),'1',substring-after($rowval,'base'))"/></xsl:with-param>
  50.       </xsl:call-template>
  51.     </xsl:when>
  52.     <xsl:when test="contains($rowval,'main')">
  53.       <xsl:call-template name="trans-level">
  54.         <xsl:with-param name="rowval"><xsl:value-of select="concat(substring-before($rowval,'main'),'2',substring-after($rowval,'main'))"/></xsl:with-param>
  55.       </xsl:call-template>
  56.     </xsl:when>
  57.     <xsl:when test="contains($rowval,'fallback')">
  58.       <xsl:call-template name="trans-level">
  59.         <xsl:with-param name="rowval"><xsl:value-of select="concat(substring-before($rowval,'fallback'),'3',substring-after($rowval,'fallback'))"/></xsl:with-param>
  60.       </xsl:call-template>
  61.     </xsl:when>
  62.     <xsl:when test="contains($rowval,'syntactic')">
  63.       <xsl:call-template name="trans-level">
  64.         <xsl:with-param name="rowval"><xsl:value-of select="concat(substring-before($rowval,'syntactic'),'4',substring-after($rowval,'syntactic'))"/></xsl:with-param>
  65.       </xsl:call-template>
  66.     </xsl:when>
  67.     <xsl:otherwise><xsl:value-of select="normalize-space($rowval)"/></xsl:otherwise>
  68.   </xsl:choose>
  69. </xsl:template>
  70.  
  71. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  72. <!--                                                                 -->
  73. <!-- This file contains a unified stylesheet for FO testcases.       -->
  74. <!-- Templates defined herein are divided into the following groups: -->
  75. <!--                                                                 -->
  76. <!-- 0. Attribute-copying templates that perform parameter           -->
  77. <!--    substitutions                                                -->
  78. <!--                                                                 -->
  79. <!-- 1. Document structure templates. They produce an output of the  -->
  80. <!--    top-level FO elements - fo:root, fo:layout-page-master, etc. -->
  81. <!--    They are more than one, since different tests require        -->
  82. <!--    different levels of top-level formatting control.            -->
  83. <!--                                                                 -->
  84. <!-- 2. Aliases for common elements, provided for brevity's sake.    -->
  85. <!--    Their attributes are copied to the resulting FO without      -->
  86. <!--    checking.                                                    -->
  87. <!--                                                                 -->
  88. <!-- 3. Handy HTML-style shortcuts for commonly used patterns -      -->
  89. <!--    ordered/unordered lists, bold/italic/underline, etc.         -->
  90. <!--                                                                 -->
  91. <!-- 4. Standard formatting elements needed in every testcase -      -->
  92. <!--    headers, annotation, remarks, etc. etc.                      -->
  93. <!--                                                                 -->
  94. <!-- 5. Special template to ensure transparent passing of FOs        -->
  95. <!--    inserted directly into the source tree.                      -->
  96. <!--                                                                 -->
  97. <!-- 6. Macro-related templates                                      -->
  98. <!--                                                                 -->
  99. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  100.  
  101. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  102. <!-- 0. Attribute copying & macro parameter substitution             -->
  103. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  104.  
  105.  
  106. <!-- =============================================================== -->
  107. <!-- Top-level attribute-copying template                            -->
  108. <!-- =============================================================== -->
  109.  
  110. <xsl:template match="@*"> &DECLARE-MACRO-PARAMETERS;
  111.   <xsl:attribute name="{name()}">
  112.     <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  113.     </xsl:call-template>
  114.   </xsl:attribute>
  115. </xsl:template>
  116.  
  117.  
  118. <!-- =============================================================== -->
  119. <!-- Main macro expansion template                                   -->
  120. <!-- =============================================================== -->
  121.  
  122. <xsl:template name="get-expanded-attribute"> &DECLARE-MACRO-PARAMETERS;
  123.  
  124.   <xsl:choose>
  125.     <!-- If the attribute value is '$arg'/'$arg1'/..., -->
  126.     <!-- replace it with a correspondent parameter     -->
  127.     <xsl:when test=".='$arg'">  <xsl:value-of select="$arg"/>  </xsl:when>
  128.     <xsl:when test=".='$arg1'"> <xsl:value-of select="$arg1"/> </xsl:when>
  129.     <xsl:when test=".='$arg2'"> <xsl:value-of select="$arg2"/> </xsl:when>
  130.     <xsl:when test=".='$arg3'"> <xsl:value-of select="$arg3"/> </xsl:when>
  131.     <xsl:when test=".='$arg4'"> <xsl:value-of select="$arg4"/> </xsl:when>
  132.     <xsl:when test=".='$arg5'"> <xsl:value-of select="$arg5"/> </xsl:when>
  133.     <xsl:when test=".='$arg6'"> <xsl:value-of select="$arg6"/> </xsl:when>
  134.     <xsl:when test=".='$arg7'"> <xsl:value-of select="$arg7"/> </xsl:when>
  135.     <xsl:when test=".='$arg8'"> <xsl:value-of select="$arg8"/> </xsl:when>
  136.     <xsl:when test=".='$arg9'"> <xsl:value-of select="$arg9"/> </xsl:when>
  137.     <xsl:when test=".='$argA'"> <xsl:value-of select="$argA"/> </xsl:when>
  138.     <xsl:when test=".='$argB'"> <xsl:value-of select="$argB"/> </xsl:when>
  139.     <xsl:when test=".='$argC'"> <xsl:value-of select="$argC"/> </xsl:when>
  140.     <xsl:when test=".='$argD'"> <xsl:value-of select="$argD"/> </xsl:when>
  141.     <xsl:when test=".='$counter'"> <xsl:value-of select="$counter"/> </xsl:when>
  142.     <xsl:when test=".='$test-number'"> <xsl:value-of select="$test-number"/> </xsl:when>
  143.  
  144.     <xsl:when test=".='$subtest-number'"> <xsl:value-of select="$subtest-number"/> </xsl:when>
  145.  
  146.     <xsl:otherwise>
  147.       <!-- Start recursive expansion of the attribute -->
  148.       <xsl:call-template name="expand-attribute-recursively">
  149.         &WITH-MACRO-PARAMETERS;
  150.         <xsl:with-param name="source-string" select="."/>
  151.       </xsl:call-template>
  152.     </xsl:otherwise>
  153.   </xsl:choose>
  154.  
  155. </xsl:template>
  156.  
  157.  
  158. <!-- =============================================================== -->
  159. <!-- Single step of recursive attribute expansion                    -->
  160. <!-- =============================================================== -->
  161.  
  162. <xsl:template name="expand-attribute-recursively">
  163.   &DECLARE-MACRO-PARAMETERS;
  164.   <xsl:param name="source-string"/>
  165.  
  166.   <xsl:choose>
  167.     <!-- If a source string contains a substring like {$arg}  -->
  168.     <!-- replace it with a parameter value and call this same -->
  169.     <!-- template once again                                  -->
  170.     <xsl:when test="contains($source-string,'{$arg}')">
  171.       <xsl:call-template name="expand-attribute-recursively">
  172.         &WITH-MACRO-PARAMETERS;
  173.         <xsl:with-param name="source-string">
  174.           <xsl:value-of select="substring-before($source-string,'{$arg}')"/>
  175.           <xsl:value-of select="$arg"/>
  176.           <xsl:value-of select="substring-after($source-string,'{$arg}')"/>
  177.         </xsl:with-param>
  178.       </xsl:call-template>
  179.     </xsl:when>
  180.  
  181.     <xsl:when test="contains($source-string,'{$arg1}')">
  182.       <xsl:call-template name="expand-attribute-recursively">
  183.         &WITH-MACRO-PARAMETERS;
  184.         <xsl:with-param name="source-string">
  185.           <xsl:value-of select="substring-before($source-string,'{$arg1}')"/>
  186.           <xsl:value-of select="$arg1"/>
  187.           <xsl:value-of select="substring-after($source-string,'{$arg1}')"/>
  188.         </xsl:with-param>
  189.       </xsl:call-template>
  190.     </xsl:when>
  191.  
  192.     <xsl:when test="contains($source-string,'{$arg2}')">
  193.       <xsl:call-template name="expand-attribute-recursively">
  194.         &WITH-MACRO-PARAMETERS;
  195.         <xsl:with-param name="source-string">
  196.           <xsl:value-of select="substring-before($source-string,'{$arg2}')"/>
  197.           <xsl:value-of select="$arg2"/>
  198.           <xsl:value-of select="substring-after($source-string,'{$arg2}')"/>
  199.         </xsl:with-param>
  200.       </xsl:call-template>
  201.     </xsl:when>
  202.  
  203.     <xsl:when test="contains($source-string,'{$arg3}')">
  204.       <xsl:call-template name="expand-attribute-recursively">
  205.         &WITH-MACRO-PARAMETERS;
  206.         <xsl:with-param name="source-string">
  207.           <xsl:value-of select="substring-before($source-string,'{$arg3}')"/>
  208.           <xsl:value-of select="$arg3"/>
  209.           <xsl:value-of select="substring-after($source-string,'{$arg3}')"/>
  210.         </xsl:with-param>
  211.       </xsl:call-template>
  212.     </xsl:when>
  213.  
  214.     <xsl:when test="contains($source-string,'{$arg4}')">
  215.       <xsl:call-template name="expand-attribute-recursively">
  216.         &WITH-MACRO-PARAMETERS;
  217.         <xsl:with-param name="source-string">
  218.           <xsl:value-of select="substring-before($source-string,'{$arg4}')"/>
  219.           <xsl:value-of select="$arg4"/>
  220.           <xsl:value-of select="substring-after($source-string,'{$arg4}')"/>
  221.         </xsl:with-param>
  222.       </xsl:call-template>
  223.     </xsl:when>
  224.  
  225.     <xsl:when test="contains($source-string,'{$arg5}')">
  226.       <xsl:call-template name="expand-attribute-recursively">
  227.         &WITH-MACRO-PARAMETERS;
  228.         <xsl:with-param name="source-string">
  229.           <xsl:value-of select="substring-before($source-string,'{$arg5}')"/>
  230.           <xsl:value-of select="$arg5"/>
  231.           <xsl:value-of select="substring-after($source-string,'{$arg5}')"/>
  232.         </xsl:with-param>
  233.       </xsl:call-template>
  234.     </xsl:when>
  235.  
  236.     <xsl:when test="contains($source-string,'{$arg6}')">
  237.       <xsl:call-template name="expand-attribute-recursively">
  238.         &WITH-MACRO-PARAMETERS;
  239.         <xsl:with-param name="source-string">
  240.           <xsl:value-of select="substring-before($source-string,'{$arg6}')"/>
  241.           <xsl:value-of select="$arg6"/>
  242.           <xsl:value-of select="substring-after($source-string,'{$arg6}')"/>
  243.         </xsl:with-param>
  244.       </xsl:call-template>
  245.     </xsl:when>
  246.  
  247.     <xsl:when test="contains($source-string,'{$arg7}')">
  248.       <xsl:call-template name="expand-attribute-recursively">
  249.         &WITH-MACRO-PARAMETERS;
  250.         <xsl:with-param name="source-string">
  251.           <xsl:value-of select="substring-before($source-string,'{$arg7}')"/>
  252.           <xsl:value-of select="$arg7"/>
  253.           <xsl:value-of select="substring-after($source-string,'{$arg7}')"/>
  254.         </xsl:with-param>
  255.       </xsl:call-template>
  256.     </xsl:when>
  257.  
  258.     <xsl:when test="contains($source-string,'{$arg8}')">
  259.       <xsl:call-template name="expand-attribute-recursively">
  260.         &WITH-MACRO-PARAMETERS;
  261.         <xsl:with-param name="source-string">
  262.           <xsl:value-of select="substring-before($source-string,'{$arg8}')"/>
  263.           <xsl:value-of select="$arg8"/>
  264.           <xsl:value-of select="substring-after($source-string,'{$arg8}')"/>
  265.         </xsl:with-param>
  266.       </xsl:call-template>
  267.     </xsl:when>
  268.  
  269.     <xsl:when test="contains($source-string,'{$arg9}')">
  270.       <xsl:call-template name="expand-attribute-recursively">
  271.         &WITH-MACRO-PARAMETERS;
  272.         <xsl:with-param name="source-string">
  273.           <xsl:value-of select="substring-before($source-string,'{$arg9}')"/>
  274.           <xsl:value-of select="$arg9"/>
  275.           <xsl:value-of select="substring-after($source-string,'{$arg9}')"/>
  276.         </xsl:with-param>
  277.       </xsl:call-template>
  278.     </xsl:when>
  279.  
  280.     <xsl:when test="contains($source-string,'{$argA}')">
  281.       <xsl:call-template name="expand-attribute-recursively">
  282.         &WITH-MACRO-PARAMETERS;
  283.         <xsl:with-param name="source-string">
  284.           <xsl:value-of select="substring-before($source-string,'{$argA}')"/>
  285.           <xsl:value-of select="$argA"/>
  286.           <xsl:value-of select="substring-after($source-string,'{$argA}')"/>
  287.         </xsl:with-param>
  288.       </xsl:call-template>
  289.     </xsl:when>
  290.  
  291.     <xsl:when test="contains($source-string,'{$argB}')">
  292.       <xsl:call-template name="expand-attribute-recursively">
  293.         &WITH-MACRO-PARAMETERS;
  294.         <xsl:with-param name="source-string">
  295.           <xsl:value-of select="substring-before($source-string,'{$argB}')"/>
  296.           <xsl:value-of select="$argB"/>
  297.           <xsl:value-of select="substring-after($source-string,'{$argB}')"/>
  298.         </xsl:with-param>
  299.       </xsl:call-template>
  300.     </xsl:when>
  301.  
  302.     <xsl:when test="contains($source-string,'{$argC}')">
  303.       <xsl:call-template name="expand-attribute-recursively">
  304.         &WITH-MACRO-PARAMETERS;
  305.         <xsl:with-param name="source-string">
  306.           <xsl:value-of select="substring-before($source-string,'{$argC}')"/>
  307.           <xsl:value-of select="$argC"/>
  308.           <xsl:value-of select="substring-after($source-string,'{$argC}')"/>
  309.         </xsl:with-param>
  310.       </xsl:call-template>
  311.     </xsl:when>
  312.  
  313.     <xsl:when test="contains($source-string,'{$argD}')">
  314.       <xsl:call-template name="expand-attribute-recursively">
  315.         &WITH-MACRO-PARAMETERS;
  316.         <xsl:with-param name="source-string">
  317.           <xsl:value-of select="substring-before($source-string,'{$argD}')"/>
  318.           <xsl:value-of select="$argD"/>
  319.           <xsl:value-of select="substring-after($source-string,'{$argD}')"/>
  320.         </xsl:with-param>
  321.       </xsl:call-template>
  322.     </xsl:when>
  323.  
  324.     <xsl:when test="contains($source-string,'{$counter}')">
  325.       <xsl:call-template name="expand-attribute-recursively">
  326.         &WITH-MACRO-PARAMETERS;
  327.         <xsl:with-param name="source-string">
  328.           <xsl:value-of select="substring-before($source-string,'{$counter}')"/>
  329.           <xsl:value-of select="$counter"/>
  330.           <xsl:value-of select="substring-after($source-string,'{$counter}')"/>
  331.         </xsl:with-param>
  332.       </xsl:call-template>
  333.     </xsl:when>
  334.  
  335.  
  336.     <xsl:when test="contains($source-string,'{$test-number}')">
  337.  
  338.       <xsl:call-template name="expand-attribute-recursively">
  339.  
  340.         &WITH-MACRO-PARAMETERS;
  341.  
  342.         <xsl:with-param name="source-string">
  343.  
  344.           <xsl:value-of select="substring-before($source-string,'{$test-number}')"/>
  345.  
  346.           <xsl:value-of select="$test-number"/>
  347.  
  348.           <xsl:value-of select="substring-after($source-string,'{$test-number}')"/>
  349.  
  350.         </xsl:with-param>
  351.  
  352.       </xsl:call-template>
  353.  
  354.     </xsl:when>
  355.  
  356.     <xsl:when test="contains($source-string,'{$subtest-number}')">
  357.  
  358.       <xsl:call-template name="expand-attribute-recursively">
  359.  
  360.         &WITH-MACRO-PARAMETERS;
  361.  
  362.         <xsl:with-param name="source-string">
  363.  
  364.           <xsl:value-of select="substring-before($source-string,'{$subtest-number}')"/>
  365.  
  366.           <xsl:value-of select="$subtest-number"/>
  367.  
  368.           <xsl:value-of select="substring-after($source-string,'{$subtest-number}')"/>
  369.  
  370.         </xsl:with-param>
  371.  
  372.       </xsl:call-template>
  373.  
  374.     </xsl:when>
  375.  
  376.     <xsl:when test="contains($source-string,'{$image-path}')">
  377.       <xsl:call-template name="expand-attribute-recursively">
  378.         &WITH-MACRO-PARAMETERS;
  379.         <xsl:with-param name="source-string">
  380.           <xsl:value-of select="substring-before($source-string,'{$image-path}')"/>
  381.           <xsl:value-of select="$image-path"/>
  382.           <xsl:value-of select="substring-after($source-string,'{$image-path}')"/>
  383.         </xsl:with-param>
  384.       </xsl:call-template>
  385.     </xsl:when>
  386.  
  387.  
  388.     <!-- If a source string contains an arithmetic expression -->
  389.     <!-- {[...]}, calculate it, paste the result into the     -->
  390.     <!-- source string and call the template once again       -->
  391.  
  392.     <xsl:when test="contains($source-string,'{[')">
  393.       <xsl:variable name="expr-and-tail"
  394.                     select="substring-after($source-string,'{[')"/>
  395.       <xsl:choose>
  396.         <xsl:when test="contains($expr-and-tail,']}')">
  397.  
  398.           <xsl:call-template name="expand-attribute-recursively">
  399.             &WITH-MACRO-PARAMETERS;
  400.             <xsl:with-param name="source-string">
  401.               <xsl:value-of select="substring-before($source-string,'{[')"/>
  402.  
  403.               <xsl:call-template name="evaluate-arithmetic">
  404.                 &WITH-MACRO-PARAMETERS;
  405.                 <xsl:with-param name="expr">
  406.                   <xsl:value-of select="normalize-space(substring-before($expr-and-tail,']}'))"/>
  407.                 </xsl:with-param>
  408.               </xsl:call-template>
  409.  
  410.               <xsl:value-of select="substring-after($expr-and-tail,']}')"/>
  411.             </xsl:with-param>
  412.           </xsl:call-template>
  413.         </xsl:when>
  414.  
  415.         <xsl:otherwise>
  416.           <!-- Unmatched '{[': not an expression, ignore and exit -->
  417.           <xsl:value-of select="$source-string"/>
  418.         </xsl:otherwise>
  419.       </xsl:choose>
  420.     </xsl:when>
  421.  
  422.     <xsl:otherwise>
  423.       <!-- No substitutable patterns found; stop recursion -->
  424.       <xsl:value-of select="$source-string"/>
  425.     </xsl:otherwise>
  426.   </xsl:choose>
  427.  
  428. </xsl:template>
  429.  
  430. <!-- =============================================================== -->
  431. <!-- Evaluate arithmetic expression in the string                    -->
  432. <!-- =============================================================== -->
  433.  
  434. <xsl:template name="evaluate-arithmetic">
  435.   &DECLARE-MACRO-PARAMETERS;
  436.   <xsl:param name="expr"/>
  437.  
  438.   <xsl:choose>
  439.     <!-- Variable instantiation -->
  440.     <xsl:when test="$expr='$arg'">  <xsl:value-of select="$arg"/>  </xsl:when>
  441.     <xsl:when test="$expr='$arg1'"> <xsl:value-of select="$arg1"/> </xsl:when>
  442.     <xsl:when test="$expr='$arg2'"> <xsl:value-of select="$arg2"/> </xsl:when>
  443.     <xsl:when test="$expr='$arg3'"> <xsl:value-of select="$arg3"/> </xsl:when>
  444.     <xsl:when test="$expr='$arg4'"> <xsl:value-of select="$arg4"/> </xsl:when>
  445.     <xsl:when test="$expr='$arg5'"> <xsl:value-of select="$arg5"/> </xsl:when>
  446.     <xsl:when test="$expr='$arg6'"> <xsl:value-of select="$arg6"/> </xsl:when>
  447.     <xsl:when test="$expr='$arg7'"> <xsl:value-of select="$arg7"/> </xsl:when>
  448.     <xsl:when test="$expr='$arg8'"> <xsl:value-of select="$arg8"/> </xsl:when>
  449.     <xsl:when test="$expr='$arg9'"> <xsl:value-of select="$arg9"/> </xsl:when>
  450.     <xsl:when test="$expr='$argA'"> <xsl:value-of select="$argA"/> </xsl:when>
  451.     <xsl:when test="$expr='$argB'"> <xsl:value-of select="$argB"/> </xsl:when>
  452.     <xsl:when test="$expr='$argC'"> <xsl:value-of select="$argC"/> </xsl:when>
  453.     <xsl:when test="$expr='$argD'"> <xsl:value-of select="$argD"/> </xsl:when>
  454.     <xsl:when test="$expr='$counter'"> <xsl:value-of select="$counter"/> </xsl:when>
  455.     <xsl:when test="$expr='$test-number'"> <xsl:value-of select="$test-number"/> </xsl:when>
  456.  
  457.     <xsl:when test="$expr='$subtest-number'"> <xsl:value-of select="$subtest-number"/> </xsl:when>
  458.  
  459.  
  460.     <!-- Addition -->
  461.     <xsl:when test="contains($expr,'+')">
  462.       <xsl:variable name="op1">
  463.         <xsl:call-template name="evaluate-arithmetic">
  464.           &WITH-MACRO-PARAMETERS;
  465.           <xsl:with-param name="expr">
  466.             <xsl:value-of select="normalize-space(substring-before($expr,'+'))"/>
  467.           </xsl:with-param>
  468.         </xsl:call-template>
  469.       </xsl:variable>
  470.       <xsl:variable name="op2">
  471.         <xsl:call-template name="evaluate-arithmetic">
  472.           &WITH-MACRO-PARAMETERS;
  473.           <xsl:with-param name="expr">
  474.             <xsl:value-of select="normalize-space(substring-after($expr,'+'))"/>
  475.           </xsl:with-param>
  476.         </xsl:call-template>
  477.       </xsl:variable>
  478.       <xsl:variable name="result" select="$op1 + $op2"/>
  479.       <xsl:value-of select="$result"/>
  480.     </xsl:when>
  481.  
  482.     <!-- Subtraction -->
  483.     <xsl:when test="contains($expr,'-')">
  484.       <xsl:variable name="op1">
  485.         <xsl:call-template name="evaluate-arithmetic">
  486.           &WITH-MACRO-PARAMETERS;
  487.           <xsl:with-param name="expr">
  488.             <xsl:value-of select="normalize-space(substring-before($expr,'-'))"/>
  489.           </xsl:with-param>
  490.         </xsl:call-template>
  491.       </xsl:variable>
  492.       <xsl:variable name="op2">
  493.         <xsl:call-template name="evaluate-arithmetic">
  494.           &WITH-MACRO-PARAMETERS;
  495.           <xsl:with-param name="expr">
  496.             <xsl:value-of select="normalize-space(substring-after($expr,'-'))"/>
  497.           </xsl:with-param>
  498.         </xsl:call-template>
  499.       </xsl:variable>
  500.       <xsl:variable name="result" select="$op1 - $op2"/>
  501.       <xsl:value-of select="$result"/>
  502.     </xsl:when>
  503.  
  504.     <!-- Multiplication -->
  505.     <xsl:when test="contains($expr,'*')">
  506.       <xsl:variable name="op1">
  507.         <xsl:call-template name="evaluate-arithmetic">
  508.           &WITH-MACRO-PARAMETERS;
  509.           <xsl:with-param name="expr">
  510.             <xsl:value-of select="normalize-space(substring-before($expr,'*'))"/>
  511.           </xsl:with-param>
  512.         </xsl:call-template>
  513.       </xsl:variable>
  514.       <xsl:variable name="op2">
  515.         <xsl:call-template name="evaluate-arithmetic">
  516.           &WITH-MACRO-PARAMETERS;
  517.           <xsl:with-param name="expr">
  518.             <xsl:value-of select="normalize-space(substring-after($expr,'*'))"/>
  519.           </xsl:with-param>
  520.         </xsl:call-template>
  521.       </xsl:variable>
  522.       <xsl:variable name="result" select="$op1 * $op2"/>
  523.       <xsl:value-of select="$result"/>
  524.     </xsl:when>
  525.  
  526.     <!-- Division -->
  527.     <xsl:when test="contains($expr,'/')">
  528.       <xsl:variable name="op1">
  529.         <xsl:call-template name="evaluate-arithmetic">
  530.           &WITH-MACRO-PARAMETERS;
  531.           <xsl:with-param name="expr">
  532.             <xsl:value-of select="normalize-space(substring-before($expr,'/'))"/>
  533.           </xsl:with-param>
  534.         </xsl:call-template>
  535.       </xsl:variable>
  536.       <xsl:variable name="op2">
  537.         <xsl:call-template name="evaluate-arithmetic">
  538.           &WITH-MACRO-PARAMETERS;
  539.           <xsl:with-param name="expr">
  540.             <xsl:value-of select="normalize-space(substring-after($expr,'/'))"/>
  541.           </xsl:with-param>
  542.         </xsl:call-template>
  543.       </xsl:variable>
  544.       <xsl:variable name="result" select="$op1 div $op2"/>
  545.       <xsl:value-of select="$result"/>
  546.     </xsl:when>
  547.  
  548.     <!-- Modulo -->
  549.     <xsl:when test="contains($expr,'%')">
  550.       <xsl:variable name="op1">
  551.         <xsl:call-template name="evaluate-arithmetic">
  552.           &WITH-MACRO-PARAMETERS;
  553.           <xsl:with-param name="expr">
  554.             <xsl:value-of select="normalize-space(substring-before($expr,'%'))"/>
  555.           </xsl:with-param>
  556.         </xsl:call-template>
  557.       </xsl:variable>
  558.       <xsl:variable name="op2">
  559.         <xsl:call-template name="evaluate-arithmetic">
  560.           &WITH-MACRO-PARAMETERS;
  561.           <xsl:with-param name="expr">
  562.             <xsl:value-of select="normalize-space(substring-after($expr,'%'))"/>
  563.           </xsl:with-param>
  564.         </xsl:call-template>
  565.       </xsl:variable>
  566.       <xsl:variable name="result" select="$op1 mod $op2"/>
  567.       <xsl:value-of select="$result"/>
  568.     </xsl:when>
  569.  
  570.     <!-- Neither operator expression nor variable: should be a number -->
  571.     <xsl:otherwise>
  572.       <xsl:value-of select="$expr"/>
  573.     </xsl:otherwise>
  574.   </xsl:choose>
  575.  
  576. </xsl:template>
  577.  
  578.  
  579.  
  580. <!-- =============================================================== -->
  581. <!--                                                                 -->
  582. <!-- Multi-pages (for documents with several simple-page-master)     -->
  583. <!--                                                                 -->
  584. <!-- =============================================================== -->
  585.  
  586.  
  587. <xsl:template match="list-page">
  588.     <fo:layout-master-set>
  589.           <xsl:apply-templates/>
  590.     </fo:layout-master-set>
  591. </xsl:template>
  592.  
  593. <xsl:template match="declare-page">
  594.       <fo:simple-page-master master-name="{@name}">
  595.         <fo:region-body region-name="xsl-region-body"
  596.                         margin="0.7in"
  597.                         column-gap="0.25in"
  598.                         border="0.25pt solid gray"
  599.                         padding="6pt"
  600.                         column-count="'{@column-count}'"
  601.                         reference-orientation="{@ref-orientation}">
  602.           <xsl:copy-of select="@column-count"/>
  603.         </fo:region-body>
  604.         <fo:region-before region-name="xsl-region-before"
  605.                           extent="0.7in"
  606.                           display-align="after"
  607.                           padding="6pt 0.7in"/>
  608.         <fo:region-after region-name="xsl-region-after"
  609.                          extent="0.7in"
  610.                          display-align="before"
  611.                          padding="6pt 0.7in"/>
  612.       </fo:simple-page-master>
  613. </xsl:template>
  614.  
  615.  
  616. <xsl:template match="page">
  617.     <fo:page-sequence master-reference="{@name}">
  618.       <fo:static-content flow-name="xsl-region-before">
  619.         <fo:list-block font="10pt Helvetica"
  620.                   provisional-distance-between-starts="5in"
  621.                   provisional-label-separation="0in">
  622.           <fo:list-item>
  623.             <fo:list-item-label end-indent="label-end()">
  624.               <fo:block text-align="start" font-weight="bold">
  625.                 <xsl:value-of select="title/*|title/text()"/>
  626.               </fo:block>
  627.             </fo:list-item-label>
  628.             <fo:list-item-body start-indent="body-start()">
  629.               <fo:block text-align="end">
  630.                 Page <fo:page-number/>
  631.               </fo:block>
  632.             </fo:list-item-body>
  633.           </fo:list-item>
  634.         </fo:list-block>
  635.       </fo:static-content>
  636.  
  637.       <fo:static-content flow-name="xsl-region-after">
  638.         <fo:list-block font="9pt Times"
  639.                   provisional-distance-between-starts="3in"
  640.                   provisional-label-separation="0in">
  641.           <fo:list-item>
  642.             <fo:list-item-label end-indent="label-end()">
  643.               <fo:block text-align="start" font-weight="bold">
  644.                 <xsl:text>© </xsl:text>
  645.                 <fo:basic-link
  646.                     external-destination="url(http://www.renderx.com/)"
  647.                     color="#0000C0"
  648.                     text-decoration="underline">
  649.                   <xsl:text>Render</xsl:text>
  650.                   <fo:wrapper font-weight="bold" color="#C00000">X</fo:wrapper>
  651.                 </fo:basic-link>
  652.                 <xsl:text> 2000</xsl:text>
  653.               </fo:block>
  654.             </fo:list-item-label>
  655.             <fo:list-item-body start-indent="body-start()">
  656.               <fo:block text-align="end" font-style="italic" color="#606060">
  657.                 XSL Formatting Objects Test Suite
  658.               </fo:block>
  659.             </fo:list-item-body>
  660.           </fo:list-item>
  661.         </fo:list-block>
  662.       </fo:static-content>
  663.  
  664.       <fo:static-content flow-name="xsl-footnote-separator">
  665.         <fo:block>
  666.            <fo:leader leader-pattern="rule"
  667.                       leader-length="100%"
  668.                       rule-thickness="0.5pt"
  669.                       rule-style="solid"
  670.                       color="black"/>
  671.          </fo:block>
  672.       </fo:static-content>
  673.  
  674.       <fo:flow flow-name="xsl-region-body">
  675.           <xsl:apply-templates/>
  676.       </fo:flow>
  677.  
  678.     </fo:page-sequence>
  679. </xsl:template>
  680.  
  681.  
  682. <xsl:template match="plain-doc-pages">
  683.  
  684.  
  685.   <xsl:comment>
  686.     (c) RenderX, 2002
  687.     This file makes part of the RenderX XSL FO Test Suite. Permission is
  688.     granted to copy and modify this file as a whole or in part, provided
  689.     that any work derived from it bear a reference to the original
  690.     document.
  691.   </xsl:comment>
  692.  
  693.   <fo:root>
  694.      <xsl:apply-templates/>
  695.   </fo:root>
  696. </xsl:template>
  697.  
  698. <!-- ================= End of multi-page section =================== -->
  699.  
  700.  
  701. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  702. <!--                                                                 -->
  703. <!-- 1. Top-level templates: various document types                  -->
  704. <!--                                                                 -->
  705. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  706.  
  707.  
  708. <!-- =============================================================== -->
  709. <!-- Most common template: a document composed of plain pages,       -->
  710. <!-- one or more columns, reasonable margins, nothing special.       -->
  711. <!-- From the second page, we add a header and a page number.        -->
  712. <!-- The header text is specified in the 'header' attribute          -->
  713. <!-- The number of columns is specified in the 'column-count'        -->
  714. <!-- attribute (default is single-column).                           -->
  715. <!-- =============================================================== -->
  716.  
  717.  
  718. <xsl:template match="plain-doc">
  719.  
  720.   <xsl:comment>
  721.     (c) RenderX, 2000
  722.     This file makes part of the RenderX XSL FO Test Suite. Permission is
  723.     granted to copy and modify this file as a whole or in part, provided
  724.     that any work derived from it bear a reference to the original
  725.     document.
  726.   </xsl:comment>
  727.  
  728.   <fo:root>
  729.     <fo:layout-master-set>
  730.       <fo:simple-page-master master-name="all-pages">
  731.         <fo:region-body region-name="xsl-region-body"
  732.                         margin="0.7in"
  733.                         column-gap="0.25in"
  734.                         border="0.25pt solid gray"
  735.                         padding="6pt">
  736.           <xsl:copy-of select="@column-count"/>
  737.         </fo:region-body>
  738.         <fo:region-before region-name="xsl-region-before"
  739.                           extent="0.7in"
  740.                           display-align="after"
  741.                           padding="6pt 0.7in"/>
  742.         <fo:region-after region-name="xsl-region-after"
  743.                          extent="0.7in"
  744.                          display-align="before"
  745.                          padding="6pt 0.7in"/>
  746.       </fo:simple-page-master>
  747.     </fo:layout-master-set>
  748.  
  749.     <fo:page-sequence master-reference="all-pages">
  750.       <fo:static-content flow-name="xsl-region-before">
  751.         <fo:list-block font="10pt Helvetica"
  752.                   provisional-distance-between-starts="5in"
  753.                   provisional-label-separation="0in">
  754.           <fo:list-item>
  755.             <fo:list-item-label end-indent="label-end()">
  756.               <fo:block text-align="start" font-weight="bold">
  757.                 <xsl:value-of select="title/*|title/text()"/>
  758.               </fo:block>
  759.             </fo:list-item-label>
  760.             <fo:list-item-body start-indent="body-start()">
  761.               <fo:block text-align="end">
  762.                 Page <fo:page-number/>
  763.               </fo:block>
  764.             </fo:list-item-body>
  765.           </fo:list-item>
  766.         </fo:list-block>
  767.       </fo:static-content>
  768.  
  769.       <fo:static-content flow-name="xsl-region-after">
  770.         <fo:list-block font="9pt Times"
  771.                   provisional-distance-between-starts="3in"
  772.                   provisional-label-separation="0in">
  773.           <fo:list-item>
  774.             <fo:list-item-label end-indent="label-end()">
  775.               <fo:block text-align="start" font-weight="bold">
  776.                 <xsl:text>© </xsl:text>
  777.                 <fo:basic-link
  778.                     external-destination="url(http://www.renderx.com/)"
  779.                     color="#0000C0"
  780.                     text-decoration="underline">
  781.                   <xsl:text>Render</xsl:text>
  782.                   <fo:wrapper font-weight="bold" color="#C00000">X</fo:wrapper>
  783.                 </fo:basic-link>
  784.                 <xsl:text> 2000</xsl:text>
  785.               </fo:block>
  786.             </fo:list-item-label>
  787.             <fo:list-item-body start-indent="body-start()">
  788.               <fo:block text-align="end" font-style="italic" color="#606060">
  789.                 XSL Formatting Objects Test Suite
  790.               </fo:block>
  791.             </fo:list-item-body>
  792.           </fo:list-item>
  793.         </fo:list-block>
  794.       </fo:static-content>
  795.  
  796.       <fo:static-content flow-name="xsl-footnote-separator">
  797.         <fo:block>
  798.            <fo:leader leader-pattern="rule"
  799.                       leader-length="100%"
  800.                       rule-thickness="0.5pt"
  801.                       rule-style="solid"
  802.                       color="black"/>
  803.          </fo:block>
  804.       </fo:static-content>
  805.  
  806.       <fo:flow flow-name="xsl-region-body">
  807.         <fo:block>
  808.           <xsl:apply-templates/>
  809.          </fo:block>
  810.       </fo:flow>
  811.  
  812.     </fo:page-sequence>
  813.   </fo:root>
  814. </xsl:template>
  815.  
  816.  
  817. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  818. <!--                                                                 -->
  819. <!-- 2. Aliases for common FOs - fo:block, fo:wrapper                -->
  820. <!--                                                                 -->
  821. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  822.  
  823. <!-- "font" is an alias for fo:wrapper -->
  824.  
  825. <xsl:template match="font">  &DECLARE-MACRO-PARAMETERS;
  826.   <fo:wrapper>
  827.     <xsl:apply-templates select="*|@*|text()"> &WITH-MACRO-PARAMETERS;
  828.     </xsl:apply-templates>
  829.   </fo:wrapper>
  830. </xsl:template>
  831.  
  832.  
  833. <!-- "p" is an alias for fo:block -->
  834.  
  835. <xsl:template match="p"> &DECLARE-MACRO-PARAMETERS;
  836.   <fo:block>
  837.     <xsl:apply-templates select="*|@*|text()"> &WITH-MACRO-PARAMETERS;
  838.     </xsl:apply-templates>
  839.   </fo:block>
  840. </xsl:template>
  841.  
  842.  
  843. <!-- "frame" is used for border/background testing -->
  844.  
  845. <xsl:template match="frame"> &DECLARE-MACRO-PARAMETERS;
  846.   <fo:block text-align="center"
  847.             font="10pt Helvetica">
  848.     <xsl:choose>
  849.       <xsl:when test="@margin or @margin-bottom"/>
  850.       <xsl:otherwise>
  851.         <xsl:attribute name="margin-bottom">12pt</xsl:attribute>
  852.       </xsl:otherwise>
  853.     </xsl:choose>
  854.  
  855.     <xsl:apply-templates select="*|@*|text()"> &WITH-MACRO-PARAMETERS;
  856.     </xsl:apply-templates>
  857.  
  858.   </fo:block>
  859. </xsl:template>
  860.  
  861.  
  862.  
  863. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  864. <!--                                                                 -->
  865. <!-- 3. HTML-style shortcuts for simple formatting                   -->
  866. <!--                                                                 -->
  867. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  868.  
  869.  
  870. <xsl:template match="b"> &DECLARE-MACRO-PARAMETERS;
  871.   <fo:wrapper font-weight="bold">
  872.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  873.     </xsl:apply-templates>
  874.   </fo:wrapper>
  875. </xsl:template>
  876.  
  877.  
  878. <xsl:template match="i"> &DECLARE-MACRO-PARAMETERS;
  879.   <fo:wrapper font-style="italic">
  880.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  881.     </xsl:apply-templates>
  882.   </fo:wrapper>
  883. </xsl:template>
  884.  
  885.  
  886. <xsl:template match="u"> &DECLARE-MACRO-PARAMETERS;
  887.   <fo:wrapper text-decoration="underline">
  888.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  889.     </xsl:apply-templates>
  890.   </fo:wrapper>
  891. </xsl:template>
  892.  
  893.  
  894.  
  895. <xsl:template match="code"> &DECLARE-MACRO-PARAMETERS;
  896.   <fo:wrapper font-family="monospace">
  897.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  898.     </xsl:apply-templates>
  899.   </fo:wrapper>
  900. </xsl:template>
  901.  
  902.  
  903. <xsl:template match="h1"> &DECLARE-MACRO-PARAMETERS;
  904.   <fo:block font="bold 14pt Helvetica"
  905.             space-before="18pt"
  906.             space-after="6pt"
  907.             keep-with-next.within-column="always"
  908.             keep-together.within-column="always"
  909.             text-align="center">
  910.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  911.     </xsl:apply-templates>
  912.   </fo:block>
  913. </xsl:template>
  914.  
  915.  
  916. <xsl:template match="h2"> &DECLARE-MACRO-PARAMETERS;
  917.   <fo:block font="bold 12pt Times"
  918.             space-before="12pt"
  919.             space-after="6pt"
  920.             keep-with-next.within-column="always"
  921.             keep-together.within-column="always"
  922.             text-align="center">
  923.     <fo:wrapper text-decoration="underline">
  924.       <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  925.       </xsl:apply-templates>
  926.     </fo:wrapper>
  927.   </fo:block>
  928. </xsl:template>
  929.  
  930.  
  931. <xsl:template match="h3"> &DECLARE-MACRO-PARAMETERS;
  932.   <fo:block font="bold 12pt Times"
  933.             space-before="6pt"
  934.             space-after="3pt"
  935.             keep-with-next.within-column="always"
  936.             keep-together.within-column="always"
  937.             text-align="start">
  938.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  939.     </xsl:apply-templates>
  940.   </fo:block>
  941. </xsl:template>
  942.  
  943.  
  944. <!-- Hyperlink. The destination is presumed external -->
  945.  
  946. <xsl:template match="a"> &DECLARE-MACRO-PARAMETERS;
  947.   <fo:basic-link external-destination="url({@href})">
  948.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  949.     </xsl:apply-templates>
  950.   </fo:basic-link>
  951. </xsl:template>
  952.  
  953.  
  954. <!-- Ordered and unordered lists. They may take any attribute -->
  955. <!-- applicable to fo:list-block                              -->
  956.  
  957. <xsl:template match="ul|ol"> &DECLARE-MACRO-PARAMETERS;
  958.   <fo:list-block space-before="6pt"
  959.                  space-after="6pt" >
  960.  
  961.     <xsl:apply-templates select="@*[name()!='label'
  962.                                 and name()!='format']"> &WITH-MACRO-PARAMETERS;
  963.     </xsl:apply-templates>
  964.  
  965.     <xsl:apply-templates select="*"> &WITH-MACRO-PARAMETERS;
  966.     </xsl:apply-templates>
  967.  
  968.   </fo:list-block>
  969. </xsl:template>
  970.  
  971.  
  972. <!-- List item for an unordered list: default bullet is '-' -->
  973. <!-- List item may take any attribute for fo:list-item      -->
  974.  
  975. <xsl:template match="ul/li"> &DECLARE-MACRO-PARAMETERS;
  976.   <fo:list-item>
  977.  
  978.     <xsl:apply-templates select="@*"> &WITH-MACRO-PARAMETERS;
  979.     </xsl:apply-templates>
  980.  
  981.     <fo:list-item-label end-indent="label-end()">
  982.       <fo:block>
  983.         <xsl:choose>
  984.           <xsl:when test="../@label">
  985.             <xsl:value-of select="../@label"/>
  986.           </xsl:when>
  987.           <xsl:otherwise>-</xsl:otherwise>
  988.         </xsl:choose>
  989.       </fo:block>
  990.     </fo:list-item-label>
  991.  
  992.     <fo:list-item-body start-indent="body-start()">
  993.       <fo:block>
  994.         <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  995.         </xsl:apply-templates>
  996.       </fo:block>
  997.     </fo:list-item-body>
  998.   </fo:list-item>
  999. </xsl:template>
  1000.  
  1001.  
  1002. <!-- List item for an ordered list: default format is 1. -->
  1003. <!-- List item may take any attribute for fo:list-item   -->
  1004.  
  1005. <xsl:template match="ol/li"> &DECLARE-MACRO-PARAMETERS;
  1006.   <fo:list-item>
  1007.  
  1008.     <xsl:apply-templates select="@*"> &WITH-MACRO-PARAMETERS;
  1009.     </xsl:apply-templates>
  1010.  
  1011.     <fo:list-item-label end-indent="label-end()">
  1012.       <fo:block>
  1013.         <xsl:choose>
  1014.           <xsl:when test="../@format">
  1015.             <xsl:number level='single'
  1016.                         count="li"
  1017.                         format="{../@format}"/>
  1018.           </xsl:when>
  1019.           <xsl:otherwise>
  1020.             <xsl:number level='single'
  1021.                         count="li"
  1022.                         format="1. "/>
  1023.  
  1024.           </xsl:otherwise>
  1025.         </xsl:choose>
  1026.       </fo:block>
  1027.     </fo:list-item-label>
  1028.  
  1029.     <fo:list-item-body start-indent="body-start()">
  1030.       <fo:block>
  1031.         <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1032.         </xsl:apply-templates>
  1033.       </fo:block>
  1034.     </fo:list-item-body>
  1035.   </fo:list-item>
  1036. </xsl:template>
  1037.  
  1038.  
  1039. <!-- Plain table. This combines fo:table and fo:table-body.   -->
  1040. <!-- Attributes are attached to fo:table.                     -->
  1041.  
  1042. <xsl:template match="table"> &DECLARE-MACRO-PARAMETERS;
  1043.   <fo:table space-before="6pt"
  1044.             space-after="6pt">
  1045.  
  1046.     <xsl:apply-templates select="@*"> &WITH-MACRO-PARAMETERS;
  1047.     </xsl:apply-templates>
  1048.  
  1049.     <fo:table-body>
  1050.       <xsl:apply-templates select="*"> &WITH-MACRO-PARAMETERS;
  1051.       </xsl:apply-templates>
  1052.     </fo:table-body>
  1053.  
  1054.   </fo:table>
  1055. </xsl:template>
  1056.  
  1057.  
  1058.  
  1059. <!-- Table row. Just an alias for <fo:table-row> -->
  1060.  
  1061. <xsl:template match="tr"> &DECLARE-MACRO-PARAMETERS;
  1062.   <fo:table-row>
  1063.  
  1064.     <xsl:apply-templates select="@*|*"> &WITH-MACRO-PARAMETERS;
  1065.     </xsl:apply-templates>
  1066.  
  1067.   </fo:table-row>
  1068. </xsl:template>
  1069.  
  1070.  
  1071. <!-- Table cell. This combines fo:table-cell and fo:block.    -->
  1072. <!-- Attributes are passed to fo:table-cell.                  -->
  1073. <xsl:template match="cell"> &DECLARE-MACRO-PARAMETERS;
  1074.  
  1075.   <fo:table-cell>
  1076.  
  1077.     <xsl:if test="not(@text-align)">
  1078.       <xsl:attribute name="text-align">start</xsl:attribute>
  1079.     </xsl:if>
  1080.  
  1081.     <xsl:if test="not(@border) and not (@border-width)">
  1082.       <xsl:attribute name="border">0.5pt solid black</xsl:attribute>
  1083.     </xsl:if>
  1084.  
  1085.     <xsl:if test="not(@padding)">
  1086.       <xsl:attribute name="padding">6pt</xsl:attribute>
  1087.     </xsl:if>
  1088.  
  1089.     <xsl:apply-templates select="@*"> &WITH-MACRO-PARAMETERS;
  1090.     </xsl:apply-templates>
  1091.  
  1092.     <fo:block>
  1093.        <xsl:apply-templates select="*|text()"> &WITH-MACRO-PARAMETERS;
  1094.        </xsl:apply-templates>
  1095.     </fo:block>
  1096.   </fo:table-cell>
  1097. </xsl:template>
  1098.  
  1099.  
  1100. <!-- Horizontal rule. It is simpler to get it as a border  -->
  1101. <!-- of an empty paragraph; to prevent it from collapsing, -->
  1102. <!-- we put a space there by using xsl:text and preserve   -->
  1103. <!-- it by setting the suitable 'white-space-collapse'     -->
  1104.  
  1105. <xsl:template match="hr">
  1106.  
  1107.   <fo:block white-space-collapse="false"
  1108.             line-height="6pt"
  1109.             space-before="6pt"
  1110.             border-top="1.5pt ridge silver">
  1111.    <xsl:text>   </xsl:text>
  1112.   </fo:block>
  1113.  
  1114. </xsl:template>
  1115.  
  1116.  
  1117. <!-- Spacer: used to separate frames in border tests. -->
  1118. <!-- Same 'white-space-collapse' technique as above.  -->
  1119.  
  1120. <xsl:template match="spacer">
  1121.   <fo:block white-space-collapse="preserve"
  1122.             line-height="12pt">
  1123.     <xsl:text>   </xsl:text>
  1124.   </fo:block>
  1125. </xsl:template>
  1126.  
  1127.  
  1128.  
  1129. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  1130. <!--                                                                 -->
  1131. <!-- 4. Predefined style elements - titles, annotations, etc         -->
  1132. <!--                                                                 -->
  1133. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  1134.  
  1135. <xsl:template match="test/title" priority="2"> &DECLARE-MACRO-PARAMETERS;
  1136.  
  1137.   <xsl:variable name="test-title-color"><xsl:choose>
  1138.  
  1139.     <xsl:when test="ancestor-or-self::*[@title-color]"><xsl:for-each select="ancestor-or-self::*[@title-color][1]"><xsl:value-of select="@title-color"/></xsl:for-each></xsl:when>
  1140.  
  1141.     <xsl:otherwise>black</xsl:otherwise>
  1142.  
  1143.   </xsl:choose></xsl:variable>
  1144.  
  1145.   <fo:block font="bold 12pt Times"
  1146.  
  1147.             color="{$test-title-color}"
  1148.  
  1149.             space-before="12pt"
  1150.  
  1151.             space-before.conditionality="discard"
  1152.  
  1153.             space-after="6pt"
  1154.  
  1155.             keep-with-next.within-column="always"
  1156.  
  1157.             keep-together.within-column="always"
  1158.  
  1159.             text-align="center"
  1160.  
  1161.             padding="3pt">
  1162.  
  1163.     <fo:wrapper text-decoration="underline">
  1164.  
  1165.       <xsl:call-template name="test-number"> &WITH-MACRO-PARAMETERS;
  1166.  
  1167.       </xsl:call-template>
  1168.  
  1169.       <xsl:text> </xsl:text>
  1170.  
  1171.       <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1172.  
  1173.       </xsl:apply-templates>
  1174.  
  1175.     </fo:wrapper>
  1176.  
  1177.   </fo:block>
  1178.  
  1179. </xsl:template>
  1180.  
  1181.  
  1182.  
  1183. <xsl:template match="subtest/title" priority="2"> &DECLARE-MACRO-PARAMETERS;
  1184.  
  1185.   <xsl:variable name="subtest-title-color"><xsl:choose>
  1186.  
  1187.     <xsl:when test="ancestor-or-self::*[@title-color]"><xsl:for-each select="ancestor-or-self::*[@title-color][1]"><xsl:value-of select="@title-color"/></xsl:for-each></xsl:when>
  1188.  
  1189.     <xsl:otherwise>black</xsl:otherwise>
  1190.  
  1191.   </xsl:choose></xsl:variable>
  1192.  
  1193.   <fo:block font="bold 12pt Times"
  1194.  
  1195.             color="{$subtest-title-color}"
  1196.  
  1197.             space-before="12pt"
  1198.  
  1199.             space-before.conditionality="discard"
  1200.  
  1201.             space-after="6pt"
  1202.  
  1203.             keep-with-next.within-column="always"
  1204.  
  1205.             keep-together.within-column="always"
  1206.  
  1207.             text-align="left"
  1208.  
  1209.             padding="3pt">
  1210.  
  1211.     <fo:wrapper font-style="italic" text-decoration="underline">
  1212.       <xsl:call-template name="subtest-number"> &WITH-MACRO-PARAMETERS;
  1213.  
  1214.       </xsl:call-template>
  1215.  
  1216.       <xsl:text> </xsl:text>
  1217.  
  1218.       <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1219.  
  1220.       </xsl:apply-templates>
  1221.  
  1222.     </fo:wrapper>
  1223.  
  1224.   </fo:block>
  1225.  
  1226. </xsl:template>
  1227.  
  1228. <xsl:template match="title" name="title"> &DECLARE-MACRO-PARAMETERS;
  1229.   <xsl:variable name="title-color"><xsl:choose>
  1230.  
  1231.     <xsl:when test="ancestor-or-self::*[@title-color]"><xsl:for-each select="ancestor-or-self::*[@title-color][1]"><xsl:value-of select="@title-color"/></xsl:for-each></xsl:when>
  1232.  
  1233.     <xsl:otherwise>black</xsl:otherwise>
  1234.  
  1235.   </xsl:choose></xsl:variable>
  1236.  
  1237.   <fo:block font="bold 14pt Helvetica"
  1238.  
  1239.             color="{$title-color}"
  1240.  
  1241.             space-before="18pt"
  1242.  
  1243.             space-before.conditionality="discard"
  1244.             space-after="6pt"
  1245.             keep-with-next.within-column="always"
  1246.             keep-together.within-column="always"
  1247.             text-align="center"
  1248.             padding="3pt"
  1249.             background-color="silver">
  1250.  
  1251.  
  1252.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1253.     </xsl:apply-templates>
  1254.  
  1255.  
  1256.   </fo:block>
  1257. </xsl:template>
  1258.  
  1259.  
  1260.  
  1261. <xsl:template match="author"> &DECLARE-MACRO-PARAMETERS;
  1262.   <fo:block font-weight="bold">
  1263.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1264.     </xsl:apply-templates>
  1265.   </fo:block>
  1266. </xsl:template>
  1267.  
  1268.  
  1269. <xsl:template match="annotation"> &DECLARE-MACRO-PARAMETERS;
  1270.   <fo:block font="italic 12pt Times"
  1271.             space-before="6pt"
  1272.             space-after="6pt"
  1273.             text-align="justify">
  1274.  
  1275.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1276.     </xsl:apply-templates>
  1277.  
  1278.   </fo:block>
  1279. </xsl:template>
  1280.  
  1281.  
  1282. <xsl:template match="text"> &DECLARE-MACRO-PARAMETERS;
  1283.   <fo:block font="12pt Times"
  1284.             space-before="6pt"
  1285.             space-after="6pt">
  1286.  
  1287.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1288.     </xsl:apply-templates>
  1289.  
  1290.   </fo:block>
  1291. </xsl:template>
  1292.  
  1293.  
  1294.  
  1295. <xsl:template match="warning"> &DECLARE-MACRO-PARAMETERS;
  1296.   <fo:block font="12pt Times"
  1297.             space-before="6pt"
  1298.             space-after="6pt"
  1299.             border="thin solid black"
  1300.             text-align="justify"
  1301.             padding="3pt">
  1302.  
  1303.     <fo:wrapper font-weight="bold"
  1304.                 color="red"
  1305.                 keep-with-next.within-line="always">
  1306.       WARNING:
  1307.     </fo:wrapper>
  1308.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1309.     </xsl:apply-templates>
  1310.  
  1311.   </fo:block>
  1312. </xsl:template>
  1313.  
  1314.  
  1315. <!-- Footnotes are numbered throughout the whole document -->
  1316. <xsl:template match="footnote"> &DECLARE-MACRO-PARAMETERS;
  1317.   <fo:footnote>
  1318.     <fo:inline baseline-shift="super"
  1319.                font-size="75%"
  1320.                keep-with-previous.within-line="always">
  1321.       <xsl:number level="any"
  1322.                   count="//footnote"
  1323.                   format="(1)"/>
  1324.     </fo:inline>
  1325.  
  1326.     <fo:footnote-body>
  1327.       <fo:list-block provisional-distance-between-starts="15pt"
  1328.                      provisional-label-separation="2pt"
  1329.                      space-before="6pt"
  1330.                      space-before.conditionality="discard"
  1331.                      line-height="1.2"
  1332.                      font="9pt Times"
  1333.  
  1334.                      start-indent="0"
  1335.  
  1336.                      text-indent="0">
  1337.         <fo:list-item>
  1338.  
  1339.           <fo:list-item-label end-indent="label-end()">
  1340.             <fo:block>
  1341.               <fo:wrapper keep-together.within-line="always"
  1342.                           font-size="75%">
  1343.                 <xsl:number level="any"
  1344.                             count="//footnote"
  1345.                             format="(1)"/>
  1346.               </fo:wrapper>
  1347.             </fo:block>
  1348.           </fo:list-item-label>
  1349.           <fo:list-item-body start-indent="body-start()">
  1350.             <fo:block padding-before="3pt">
  1351.               <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1352.               </xsl:apply-templates>
  1353.             </fo:block>
  1354.           </fo:list-item-body>
  1355.         </fo:list-item>
  1356.       </fo:list-block>
  1357.     </fo:footnote-body>
  1358.   </fo:footnote>
  1359. </xsl:template>
  1360.  
  1361. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  1362. <!--                                                                 -->
  1363. <!-- 5. Pass all fo:*/rx:*/svg:* through, with all their attributes  -->
  1364. <!--                                                                 -->
  1365. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  1366.  
  1367. <xsl:template match="fo:root |
  1368.                      fo:declarations |
  1369.                      fo:color-profile |
  1370.                      fo:page-sequence |
  1371.                      fo:layout-master-set |
  1372.                      fo:page-sequence-master |
  1373.                      fo:single-page-master-reference |
  1374.                      fo:repeatable-page-master-reference |
  1375.                      fo:repeatable-page-master-alternatives |
  1376.                      fo:conditional-page-master-reference |
  1377.                      fo:simple-page-master |
  1378.                      fo:region-body |
  1379.                      fo:region-before |
  1380.                      fo:region-after |
  1381.                      fo:region-start |
  1382.                      fo:region-end |
  1383.                      fo:flow |
  1384.                      fo:static-content |
  1385.                      fo:title |
  1386.                      fo:block |
  1387.                      fo:block-container |
  1388.                      fo:bidi-override |
  1389.                      fo:character |
  1390.                      fo:initial-property-set |
  1391.                      fo:external-graphic |
  1392.                      fo:instream-foreign-object |
  1393.                      fo:inline |
  1394.                      fo:inline-container |
  1395.                      fo:leader |
  1396.                      fo:page-number |
  1397.                      fo:page-number-citation |
  1398.                      fo:table-and-caption |
  1399.                      fo:table|
  1400.                      fo:table-caption |
  1401.                      fo:table-column |
  1402.                      fo:table-header |
  1403.                      fo:table-footer |
  1404.                      fo:table-body |
  1405.                      fo:table-row |
  1406.                      fo:table-cell |
  1407.                      fo:list-block |
  1408.                      fo:list-item |
  1409.                      fo:list-item-body |
  1410.                      fo:list-item-label |
  1411.                      fo:basic-link |
  1412.                      fo:multi-switch |
  1413.                      fo:multi-case |
  1414.                      fo:multi-toggle |
  1415.                      fo:multi-properties |
  1416.                      fo:multi-property-set |
  1417.                      fo:float |
  1418.                      fo:footnote |
  1419.                      fo:footnote-body |
  1420.                      fo:wrapper |
  1421.                      fo:marker |
  1422.                      fo:retrieve-marker |
  1423.                      rx:flow-section |
  1424.                      rx:meta-info |
  1425.                      rx:meta-field |
  1426.                      rx:outline |
  1427.                      rx:bookmark |
  1428.                      rx:bookmark-label |
  1429.                      rx:page-index"> &DECLARE-MACRO-PARAMETERS;
  1430.   <xsl:copy>
  1431.     <xsl:apply-templates select="*|@*|text()"> &WITH-MACRO-PARAMETERS;
  1432.     </xsl:apply-templates>
  1433.   </xsl:copy>
  1434. </xsl:template>
  1435.  
  1436.  
  1437. <!-- SVG can occur inside fo:foreign-object -->
  1438. <xsl:template match="svg:svg |
  1439.                      svg:g |
  1440.                      svg:defs |
  1441.                      svg:desc |
  1442.                      svg:title |
  1443.                      svg:symbol |
  1444.                      svg:use |
  1445.                      svg:image |
  1446.                      svg:switch |
  1447.                      svg:style |
  1448.                      svg:path |
  1449.                      svg:rect |
  1450.                      svg:circle |
  1451.                      svg:ellipse |
  1452.                      svg:line |
  1453.                      svg:polyline |
  1454.                      svg:polygon |
  1455.                      svg:text |
  1456.                      svg:tspan |
  1457.                      svg:tref |
  1458.                      svg:glyphRun |
  1459.                      svg:textPath |
  1460.                      svg:altGlyph |
  1461.                      svg:altGlyphDef |
  1462.                      svg:altGlyphItem |
  1463.                      svg:glyphRef |
  1464.                      svg:marker |
  1465.                      svg:color-profile |
  1466.                      svg:color-profile-src |
  1467.                      svg:linearGradient |
  1468.                      svg:radialGradient |
  1469.                      svg:stop |
  1470.                      svg:pattern |
  1471.                      svg:clipPath |
  1472.                      svg:mask |
  1473.                      svg:filter |
  1474.                      svg:feDistantLight |
  1475.                      svg:fePointLight |
  1476.                      svg:feSpotLight |
  1477.                      svg:feBlend |
  1478.                      svg:feColorMatrix |
  1479.                      svg:feComponentTransfer |
  1480.                      svg:feFuncR |
  1481.                      svg:feFuncG |
  1482.                      svg:feFuncB |
  1483.                      svg:feFuncA |
  1484.                      svg:feComposite |
  1485.                      svg:feConvolveMatrix |
  1486.                      svg:feDiffuseLighting |
  1487.                      svg:feDisplacementMap |
  1488.                      svg:feFlood |
  1489.                      svg:feGaussianBlur |
  1490.                      svg:feImage |
  1491.                      svg:feMerge |
  1492.                      svg:feMergeNode |
  1493.                      svg:feMorphology |
  1494.                      svg:feOffset |
  1495.                      svg:feSpecularLighting |
  1496.                      svg:feTile |
  1497.                      svg:feTurbulence |
  1498.                      svg:cursor |
  1499.                      svg:a |
  1500.                      svg:view |
  1501.                      svg:script |
  1502.                      svg:animate |
  1503.                      svg:set |
  1504.                      svg:animateMotion |
  1505.                      svg:mpath |
  1506.                      svg:animateColor |
  1507.                      svg:animateTransform |
  1508.                      svg:font |
  1509.                      svg:glyph |
  1510.                      svg:missing-glyph |
  1511.                      svg:hkern |
  1512.                      svg:vkern |
  1513.                      svg:font-face |
  1514.                      svg:font-face-src |
  1515.                      svg:font-face-uri |
  1516.                      svg:font-face-format |
  1517.                      svg:font-face-name |
  1518.                      svg:definition-src |
  1519.                      svg:metadata |
  1520.                      svg:foreignObject"> &DECLARE-MACRO-PARAMETERS;
  1521.   <xsl:copy>
  1522.     <xsl:apply-templates select="*|@*|text()"> &WITH-MACRO-PARAMETERS;
  1523.     </xsl:apply-templates>
  1524.   </xsl:copy>
  1525. </xsl:template>
  1526.  
  1527. <!-- Default rule to complain about unrecognized objects -->
  1528.  
  1529. <xsl:template match="*" priority="-1"> &DECLARE-MACRO-PARAMETERS;
  1530.   <xsl:message>Unknown object: <xsl:value-of select="name()"/></xsl:message>
  1531.   <xsl:copy>
  1532.     <xsl:apply-templates select="*|@*|text()"> &WITH-MACRO-PARAMETERS;
  1533.     </xsl:apply-templates>
  1534.   </xsl:copy>
  1535. </xsl:template>
  1536.  
  1537.  
  1538. <xsl:template match="rdf:RDF | rdf:Descriptor"/>
  1539.  
  1540.  
  1541. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  1542. <!--                                                                 -->
  1543. <!-- 6. Macro templates.                                             -->
  1544. <!--                                                                 -->
  1545. <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
  1546.  
  1547.  
  1548. <!-- =============================================================== -->
  1549. <!-- Macro definition: resolves to nothing.                          -->
  1550. <!-- =============================================================== -->
  1551.  
  1552. <xsl:template match="define-macro"/>
  1553. <xsl:template match="define-macro" mode="get-page-master"/>
  1554.  
  1555. <!-- =============================================================== -->
  1556. <!-- Macro call: start the recursion loop over repetitions           -->
  1557. <!-- =============================================================== -->
  1558.  
  1559.  
  1560. <xsl:template match="macro"> &DECLARE-MACRO-PARAMETERS;
  1561.   <xsl:variable name="repeat-times">
  1562.     <xsl:choose>
  1563.       <xsl:when test="@repeat">
  1564.         <xsl:for-each select="@repeat">
  1565.           <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1566.           </xsl:call-template>
  1567.         </xsl:for-each>
  1568.       </xsl:when>
  1569.       <xsl:otherwise>1</xsl:otherwise>
  1570.     </xsl:choose>
  1571.   </xsl:variable>
  1572.  
  1573.   <xsl:call-template name="expand-macro-loop">
  1574.     &WITH-MACRO-PARAMETERS;
  1575.     <xsl:with-param name="step-number" select="1"/>
  1576.     <xsl:with-param name="steps-to-go" select="$repeat-times"/>
  1577.   </xsl:call-template>
  1578.  
  1579. </xsl:template>
  1580.  
  1581. <!-- =============================================================== -->
  1582. <!-- This template manages macro repetition; called recursively      -->
  1583. <!-- =============================================================== -->
  1584.  
  1585.  
  1586. <xsl:template name="expand-macro-loop">
  1587.   &DECLARE-MACRO-PARAMETERS;
  1588.   <xsl:param name="step-number"/>
  1589.   <xsl:param name="steps-to-go"/>
  1590.  
  1591.   <xsl:call-template name="expand-macro">
  1592.     &WITH-MACRO-PARAMETERS;
  1593.     <xsl:with-param name="step-number" select="$step-number"/>
  1594.   </xsl:call-template>
  1595.  
  1596.   <xsl:if test="$steps-to-go > 1">
  1597.     <xsl:call-template name="expand-macro-loop">
  1598.       &WITH-MACRO-PARAMETERS;
  1599.       <xsl:with-param name="step-number" select="$step-number + 1"/>
  1600.       <xsl:with-param name="steps-to-go" select="$steps-to-go - 1"/>
  1601.     </xsl:call-template>
  1602.   </xsl:if>
  1603. </xsl:template>
  1604.  
  1605. <!-- =============================================================== -->
  1606. <!-- This performs real macro expansion. We need a $step-number      -->
  1607. <!-- variable, because $counter must keep its previous               -->
  1608. <!-- value in order to expand macro arguments properly.              -->
  1609. <!-- =============================================================== -->
  1610.  
  1611. <xsl:template name="expand-macro">
  1612.   &DECLARE-MACRO-PARAMETERS;
  1613.   <xsl:param name="step-number"/>
  1614.  
  1615.   <xsl:variable name="macroname">
  1616.     <xsl:for-each select="@name">
  1617.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1618.       </xsl:call-template>
  1619.     </xsl:for-each>
  1620.   </xsl:variable>
  1621.  
  1622.   <xsl:variable name="macroarg">
  1623.     <xsl:for-each select="@arg">
  1624.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1625.       </xsl:call-template>
  1626.     </xsl:for-each>
  1627.   </xsl:variable>
  1628.  
  1629.   <xsl:variable name="macroarg1">
  1630.     <xsl:for-each select="@arg1">
  1631.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1632.       </xsl:call-template>
  1633.     </xsl:for-each>
  1634.   </xsl:variable>
  1635.  
  1636.   <xsl:variable name="macroarg2">
  1637.     <xsl:for-each select="@arg2">
  1638.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1639.       </xsl:call-template>
  1640.     </xsl:for-each>
  1641.   </xsl:variable>
  1642.  
  1643.   <xsl:variable name="macroarg3">
  1644.     <xsl:for-each select="@arg3">
  1645.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1646.       </xsl:call-template>
  1647.     </xsl:for-each>
  1648.   </xsl:variable>
  1649.  
  1650.   <xsl:variable name="macroarg4">
  1651.     <xsl:for-each select="@arg4">
  1652.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1653.       </xsl:call-template>
  1654.     </xsl:for-each>
  1655.   </xsl:variable>
  1656.  
  1657.  
  1658.   <xsl:variable name="macroarg5">
  1659.     <xsl:for-each select="@arg5">
  1660.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1661.       </xsl:call-template>
  1662.     </xsl:for-each>
  1663.   </xsl:variable>
  1664.  
  1665.   <xsl:variable name="macroarg6">
  1666.     <xsl:for-each select="@arg6">
  1667.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1668.       </xsl:call-template>
  1669.     </xsl:for-each>
  1670.   </xsl:variable>
  1671.  
  1672.   <xsl:variable name="macroarg7">
  1673.     <xsl:for-each select="@arg7">
  1674.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1675.       </xsl:call-template>
  1676.     </xsl:for-each>
  1677.   </xsl:variable>
  1678.  
  1679.   <xsl:variable name="macroarg8">
  1680.     <xsl:for-each select="@arg8">
  1681.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1682.       </xsl:call-template>
  1683.     </xsl:for-each>
  1684.   </xsl:variable>
  1685.  
  1686.   <xsl:variable name="macroarg9">
  1687.     <xsl:for-each select="@arg9">
  1688.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1689.       </xsl:call-template>
  1690.     </xsl:for-each>
  1691.   </xsl:variable>
  1692.  
  1693.   <xsl:variable name="macroargA">
  1694.     <xsl:for-each select="@argA">
  1695.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1696.       </xsl:call-template>
  1697.     </xsl:for-each>
  1698.   </xsl:variable>
  1699.  
  1700.   <xsl:variable name="macroargB">
  1701.     <xsl:for-each select="@argB">
  1702.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1703.       </xsl:call-template>
  1704.     </xsl:for-each>
  1705.   </xsl:variable>
  1706.  
  1707.   <xsl:variable name="macroargC">
  1708.     <xsl:for-each select="@argC">
  1709.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1710.       </xsl:call-template>
  1711.     </xsl:for-each>
  1712.   </xsl:variable>
  1713.  
  1714.   <xsl:variable name="macroargD">
  1715.     <xsl:for-each select="@argD">
  1716.       <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1717.       </xsl:call-template>
  1718.     </xsl:for-each>
  1719.   </xsl:variable>
  1720.  
  1721.  
  1722.   <xsl:for-each select="//define-macro">
  1723.     <xsl:if test="@name=$macroname">
  1724.       <xsl:apply-templates select="node()">
  1725.         <xsl:with-param name="arg"  select="$macroarg"/>
  1726.         <xsl:with-param name="arg1" select="$macroarg1"/>
  1727.         <xsl:with-param name="arg2" select="$macroarg2"/>
  1728.         <xsl:with-param name="arg3" select="$macroarg3"/>
  1729.         <xsl:with-param name="arg4" select="$macroarg4"/>
  1730.         <xsl:with-param name="arg5" select="$macroarg5"/>
  1731.         <xsl:with-param name="arg6" select="$macroarg6"/>
  1732.         <xsl:with-param name="arg7" select="$macroarg7"/>
  1733.         <xsl:with-param name="arg8" select="$macroarg8"/>
  1734.         <xsl:with-param name="arg9" select="$macroarg9"/>
  1735.         <xsl:with-param name="argA" select="$macroargA"/>
  1736.         <xsl:with-param name="argB" select="$macroargB"/>
  1737.         <xsl:with-param name="argC" select="$macroargC"/>
  1738.         <xsl:with-param name="argD" select="$macroargD"/>
  1739.         <xsl:with-param name="counter" select="$step-number"/>
  1740.  
  1741.       </xsl:apply-templates>
  1742.     </xsl:if>
  1743.   </xsl:for-each>
  1744. </xsl:template>
  1745.  
  1746.  
  1747. <!-- =============================================================== -->
  1748. <!-- Parameter substitution templates                                -->
  1749. <!-- =============================================================== -->
  1750.  
  1751.  
  1752. <xsl:template match="arg">
  1753.   <xsl:param name="arg"/>
  1754.   <xsl:value-of select="$arg"/>
  1755. </xsl:template>
  1756.  
  1757. <xsl:template match="arg1">
  1758.   <xsl:param name="arg1"/>
  1759.   <xsl:value-of select="$arg1"/>
  1760. </xsl:template>
  1761.  
  1762. <xsl:template match="arg2">
  1763.   <xsl:param name="arg2"/>
  1764.   <xsl:value-of select="$arg2"/>
  1765. </xsl:template>
  1766.  
  1767. <xsl:template match="arg3">
  1768.   <xsl:param name="arg3"/>
  1769.   <xsl:value-of select="$arg3"/>
  1770. </xsl:template>
  1771.  
  1772. <xsl:template match="arg4">
  1773.   <xsl:param name="arg4"/>
  1774.   <xsl:value-of select="$arg4"/>
  1775. </xsl:template>
  1776.  
  1777. <xsl:template match="arg5">
  1778.   <xsl:param name="arg5"/>
  1779.   <xsl:value-of select="$arg5"/>
  1780. </xsl:template>
  1781.  
  1782. <xsl:template match="arg6">
  1783.   <xsl:param name="arg6"/>
  1784.   <xsl:value-of select="$arg6"/>
  1785. </xsl:template>
  1786.  
  1787. <xsl:template match="arg7">
  1788.   <xsl:param name="arg7"/>
  1789.   <xsl:value-of select="$arg7"/>
  1790. </xsl:template>
  1791.  
  1792. <xsl:template match="arg8">
  1793.   <xsl:param name="arg8"/>
  1794.   <xsl:value-of select="$arg8"/>
  1795. </xsl:template>
  1796.  
  1797. <xsl:template match="arg9">
  1798.   <xsl:param name="arg9"/>
  1799.   <xsl:value-of select="$arg9"/>
  1800. </xsl:template>
  1801.  
  1802. <xsl:template match="argA">
  1803.   <xsl:param name="argA"/>
  1804.   <xsl:value-of select="$argA"/>
  1805. </xsl:template>
  1806.  
  1807. <xsl:template match="argB">
  1808.   <xsl:param name="argB"/>
  1809.   <xsl:value-of select="$argB"/>
  1810. </xsl:template>
  1811.  
  1812. <xsl:template match="argC">
  1813.   <xsl:param name="argC"/>
  1814.   <xsl:value-of select="$argC"/>
  1815. </xsl:template>
  1816.  
  1817. <xsl:template match="argD">
  1818.   <xsl:param name="argD"/>
  1819.   <xsl:value-of select="$argD"/>
  1820. </xsl:template>
  1821.  
  1822. <xsl:template match="counter">
  1823.   <xsl:param name="counter"/>
  1824.   <xsl:value-of select="$counter"/>
  1825. </xsl:template>
  1826.  
  1827.  
  1828. <!-- =============================================================== -->
  1829. <!-- This template generates a text from an arithmetic expression    -->
  1830. <!-- =============================================================== -->
  1831.  
  1832. <xsl:template match="formula"> &DECLARE-MACRO-PARAMETERS;
  1833.   <xsl:call-template name="evaluate-arithmetic">
  1834.     &WITH-MACRO-PARAMETERS;
  1835.     <xsl:with-param name="expr" select="@expr"/>
  1836.   </xsl:call-template>
  1837. </xsl:template>
  1838.  
  1839.  
  1840. <!-- =============================================================== -->
  1841. <!-- Repetition template: loop start                                 -->
  1842. <!-- =============================================================== -->
  1843.  
  1844. <xsl:template match="repeat"> &DECLARE-MACRO-PARAMETERS;
  1845.  
  1846.   <xsl:variable name="repeat-from">
  1847.     <xsl:choose>
  1848.       <xsl:when test="@from">
  1849.         <xsl:for-each select="@from">
  1850.           <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1851.           </xsl:call-template>
  1852.         </xsl:for-each>
  1853.       </xsl:when>
  1854.       <xsl:otherwise>1</xsl:otherwise>
  1855.     </xsl:choose>
  1856.   </xsl:variable>
  1857.  
  1858.   <xsl:variable name="repeat-step">
  1859.     <xsl:choose>
  1860.       <xsl:when test="@step">
  1861.         <xsl:for-each select="@step">
  1862.           <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1863.           </xsl:call-template>
  1864.         </xsl:for-each>
  1865.       </xsl:when>
  1866.       <xsl:otherwise>1</xsl:otherwise>
  1867.     </xsl:choose>
  1868.   </xsl:variable>
  1869.  
  1870.   <xsl:variable name="repeat-to">
  1871.     <xsl:choose>
  1872.       <xsl:when test="@times">
  1873.         <xsl:variable name="repeat-times">
  1874.           <xsl:for-each select="@times">
  1875.             <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1876.             </xsl:call-template>
  1877.           </xsl:for-each>
  1878.         </xsl:variable>
  1879.         <xsl:value-of select="$repeat-from + ($repeat-step * $repeat-times) - $repeat-step"/>
  1880.       </xsl:when>
  1881.  
  1882.       <xsl:when test="@to">
  1883.         <xsl:for-each select="@to">
  1884.           <xsl:call-template name="get-expanded-attribute"> &WITH-MACRO-PARAMETERS;
  1885.           </xsl:call-template>
  1886.         </xsl:for-each>
  1887.       </xsl:when>
  1888.  
  1889.  
  1890.       <xsl:otherwise>
  1891.         <xsl:value-of select="$repeat-from"/>
  1892.       </xsl:otherwise>
  1893.     </xsl:choose>
  1894.   </xsl:variable>
  1895.  
  1896.  
  1897.   <xsl:call-template name="expand-repetition-loop">
  1898.     &WITH-MACRO-PARAMETERS-NO-COUNTER;
  1899.     <xsl:with-param name="counter" select="$repeat-from"/>
  1900.     <xsl:with-param name="repeat-to" select="$repeat-to"/>
  1901.     <xsl:with-param name="step" select="$repeat-step"/>
  1902.  
  1903.   </xsl:call-template>
  1904.  
  1905. </xsl:template>
  1906.  
  1907. <!-- =============================================================== -->
  1908. <!-- Single recursion step for repetition loop                       -->
  1909. <!-- =============================================================== -->
  1910.  
  1911. <xsl:template name="expand-repetition-loop">
  1912.   &DECLARE-MACRO-PARAMETERS;
  1913.   <xsl:param name="repeat-to"/>
  1914.   <xsl:param name="step"/>
  1915.  
  1916.   <xsl:variable name="next-counter" select="$counter + $step"/>
  1917.  
  1918.   <!-- Generate one more instance of the repeated text -->
  1919.   <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  1920.   </xsl:apply-templates>
  1921.  
  1922.   <xsl:choose>
  1923.     <!-- Check if it is time to stop recursion -->
  1924.     <xsl:when test ="$next-counter > $repeat-to and $step > 0"/>
  1925.     <xsl:when test ="$next-counter < $repeat-to and $step < 0"/>
  1926.  
  1927.     <!-- Calculate new iteration parameters and continue recursion -->
  1928.     <xsl:otherwise>
  1929.       <xsl:call-template name="expand-repetition-loop">
  1930.         &WITH-MACRO-PARAMETERS-NO-COUNTER;
  1931.         <xsl:with-param name="counter" select="$next-counter"/>
  1932.         <xsl:with-param name="repeat-to" select="$repeat-to"/>
  1933.         <xsl:with-param name="step" select="$step"/>
  1934.       </xsl:call-template>
  1935.     </xsl:otherwise>
  1936.  
  1937.   </xsl:choose>
  1938. </xsl:template>
  1939.  
  1940. <!-- =============================================================== -->
  1941.  
  1942. <!-- Test and test number                                            -->
  1943.  
  1944. <!-- =============================================================== -->
  1945.  
  1946.  
  1947.  
  1948. <xsl:template match="test"> &DECLARE-MACRO-PARAMETERS;
  1949.  
  1950.   <xsl:variable name="curlevel"><xsl:choose>
  1951.  
  1952.       <xsl:when test="@level"><xsl:call-template name="trans-level"><xsl:with-param name="rowval"><xsl:value-of select="normalize-space(@level)"/></xsl:with-param></xsl:call-template></xsl:when>
  1953.  
  1954.       <xsl:otherwise>1</xsl:otherwise>
  1955.  
  1956.     </xsl:choose>
  1957.  
  1958.   </xsl:variable>
  1959.  
  1960.   <xsl:if test="contains($dlevel,$curlevel)">
  1961.  
  1962.     <xsl:variable name="break">
  1963.  
  1964.       <xsl:choose>
  1965.  
  1966.         <xsl:when test="@break"><xsl:value-of select="@break"/></xsl:when>
  1967.  
  1968.         <xsl:otherwise>column</xsl:otherwise>
  1969.  
  1970.       </xsl:choose>
  1971.  
  1972.     </xsl:variable>
  1973.  
  1974.     <fo:block break-after="{$break}">
  1975.  
  1976.       <xsl:variable name="test-n"><xsl:number count="test[(@level and contains($dlevel,@level)) or (not(@level) and contains($dlevel,'1'))]" format="1."/></xsl:variable>
  1977.  
  1978.       <xsl:apply-templates> &WITH-MACRO-PARAMETERS-NO-TEST-NUMBER;
  1979.  
  1980.         <xsl:with-param name="test-number" select="$test-n"/>
  1981.  
  1982.       </xsl:apply-templates>
  1983.  
  1984.     </fo:block>
  1985.  
  1986.   </xsl:if>
  1987.  
  1988. </xsl:template>
  1989.  
  1990.  
  1991.  
  1992. <xsl:template match="subtest"> &DECLARE-MACRO-PARAMETERS;
  1993.  
  1994.   <xsl:variable name="cursublevel"><xsl:choose>
  1995.  
  1996.       <xsl:when test="@level"><xsl:call-template name="trans-level"><xsl:with-param name="rowval"><xsl:value-of select="normalize-space(@level)"/></xsl:with-param></xsl:call-template></xsl:when>
  1997.  
  1998.       <xsl:otherwise><xsl:value-of select="$dlevel"/></xsl:otherwise>
  1999.  
  2000.     </xsl:choose>
  2001.  
  2002.   </xsl:variable>
  2003.  
  2004.   <xsl:if test="contains($dlevel,$cursublevel)">
  2005.  
  2006.     <xsl:variable name="subbreak">
  2007.  
  2008.       <xsl:choose>
  2009.  
  2010.         <xsl:when test="@break"><xsl:value-of select="@break"/></xsl:when>
  2011.  
  2012.         <xsl:otherwise>auto</xsl:otherwise>
  2013.  
  2014.       </xsl:choose>
  2015.  
  2016.     </xsl:variable>
  2017.  
  2018.     <fo:block break-after="{$subbreak}">
  2019.  
  2020.       <xsl:variable name="subtest-n"><xsl:number count="subtest[(@level and contains($dlevel,@level)) or (not(@level))]" format="1."/></xsl:variable>
  2021.  
  2022.       <xsl:apply-templates> &WITH-MACRO-PARAMETERS-NO-SUBTEST-NUMBER;
  2023.  
  2024.         <xsl:with-param name="subtest-number" select="$subtest-n"/>
  2025.  
  2026.       </xsl:apply-templates>
  2027.  
  2028.     </fo:block>
  2029.  
  2030.   </xsl:if>
  2031.  
  2032. </xsl:template>
  2033.  
  2034.  
  2035.  
  2036. <xsl:template match="test-number" name="test-number">
  2037.  
  2038.   <xsl:param name="test-number"/>
  2039.  
  2040.   <xsl:value-of select="$test-number"/>
  2041.  
  2042. </xsl:template>
  2043.  
  2044.  
  2045.  
  2046. <xsl:template match="subtest-number" name="subtest-number">
  2047.  
  2048.   <xsl:param name="test-number"/>
  2049.  
  2050.   <xsl:param name="subtest-number"/>
  2051.  
  2052.   <xsl:value-of select="concat($test-number,$subtest-number)"/>
  2053.  
  2054. </xsl:template>
  2055.  
  2056.  
  2057.  
  2058. <xsl:template match="level"> &DECLARE-MACRO-PARAMETERS;
  2059.  
  2060.   <xsl:variable name="curllevel"><xsl:choose>
  2061.  
  2062.       <xsl:when test="@level"><xsl:call-template name="trans-level"><xsl:with-param name="rowval"><xsl:value-of select="normalize-space(@level)"/></xsl:with-param></xsl:call-template></xsl:when>
  2063.  
  2064.       <xsl:otherwise>1</xsl:otherwise>
  2065.  
  2066.     </xsl:choose>
  2067.  
  2068.   </xsl:variable>
  2069.  
  2070.   <xsl:if test="contains($dlevel,$curllevel)">
  2071.  
  2072.     <xsl:apply-templates> &WITH-MACRO-PARAMETERS;
  2073.  
  2074.     </xsl:apply-templates>
  2075.  
  2076.   </xsl:if>
  2077.  
  2078. </xsl:template>
  2079.  
  2080.  
  2081.  
  2082. <xsl:template match="@title-color" priority="2"/>
  2083.  
  2084.  
  2085.  
  2086.  
  2087. </xsl:stylesheet>
  2088.  
  2089.