xsl-list
[Top] [All Lists]

RE: Noob: how to use "for each" in this context?

2003-09-17 01:44:32
Hi,

I realised i am repeating this code in my .xsl:
------------------------------------------
     <fo:table-cell border="solid black 1 px" 
border-collapse="collapse">
         <fo:block>
          <xsl:choose>
         <!--Here we put nothing if nodevalue=null -->
          <xsl:when test='($node="null")'></xsl:when>
        <!--or the value-->
         <xsl:otherwise><xsl:value-of select="$node"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
------------------------------------
Now i want to use a for each, how do i do that?



BTW:
My .xml
--------------------------------------------------------
<Root>
<Table>
<Row>
<nodeA>Total</nodeA>
<node1>null</node1>
<node2>777</node2>
etc

Recursion

  <xsl:template match="Row">
    <fo:table-row>
      <fo:table-cell border="solid black 1 px" border-collapse="collapse">
        <fo:block>
          <xsl:value-of select="nodeA"/>
        </fo:block>
      </fo:table-cell>
      <xsl:call-template name="cell"/>
    </fo:table-row>
  </xsl:template>
  <xsl:template name="cell">
    <xsl:param name="counter" select="1"/>
    <xsl:param name="max" select="12"/>
    <fo:table-cell border="solid black 1 px" border-collapse="collapse">
      <fo:block>
        <xsl:variable name="cell" select="*[name() = concat('node', 
$counter)]"/>
        <xsl:choose>
          <xsl:when test="not($cell = 'null')">
            <xsl:value-of select="$cell"/>
          </xsl:when>
        </xsl:choose>
      </fo:block>
    </fo:table-cell>
    <xsl:if test="$counter &lt; $max">
      <xsl:call-template name="cell">
        <xsl:with-param name="counter" select="$counter + 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

Cheers,

Jarno - Haujobb: Depths

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list