Re: [xsl] Noob: how to use "for each" in this context?

Subject: Re: [xsl] Noob: how to use "for each" in this context?
From: "Barry van Weldam" <barry@xxxxxxx>
Date: Wed, 17 Sep 2003 11:10:32 +0200
thks guys,

Gonna try your suggestions and see if i can follow it

as for the xml-data it is just the structure i showed. The nodes have actually very 'long' descriptive names.

Furthermore, the xml file isn't generated by me. I just have to style the data. 

My experience with .xml is in combination with flash mx & php. And now i am taking a dive into XSL(-fo)




----- Original Message ----- 
From: "Jim Fuller" <jim.fuller@xxxxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, September 17, 2003 10:46 AM
Subject: RE: [xsl] Noob: how to use "for each" in this context?


no need for xsl:for-each try nesting your templates

<xsl:template match="Row">
     <fo:table-cell border="solid black 1 px" border-collapse="collapse">
         <fo:block>
<xsl:apply-templates select="."/>
         </fo:block> 
     </fo:table-cell>
</xsl:template>

then supply other matching templates

<xsl:template match="NodeA">
</xsl:template>

<xsl:template match="Node1">
</xsl:template>

though I suspect that you may want to take a look at restructering your xml data.....be descriptive with your element names... is your data really data-centric instead of document centric or have you just got into the habit of thinking of data in tables and rows ?

try the following sites for more information

www.dpawson.co.uk
http://www.w3.org/Style/XSL/
www.topxml.com

gl, jim fuller


-----Original Message-----
From: Barry van Weldam [mailto:barry@xxxxxxx]
Sent: 17 September 2003 09:29
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Noob: how to use "for each" in this context?


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

and this is the part of the .xsl i want to streamline


------------------------------------------------------------------------------
 <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> 
     <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='(node1="null")'></xsl:when>
          <xsl:otherwise><xsl:value-of select="node1"/></xsl:otherwise>
         </xsl:choose>
           
         </fo:block> 
     </fo:table-cell>
     <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='(node2="null")'></xsl:when>
        <xsl:otherwise> <xsl:value-of select="node2"/></xsl:otherwise>
        </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node3="null")'></xsl:when>
        <xsl:otherwise> <xsl:value-of select="node3"/></xsl:otherwise>
        </xsl:choose> 
        </fo:block>
     </fo:table-cell> 
     <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='(node4="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node4"/></xsl:otherwise>
         </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node5="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node5"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node6="null")'></xsl:when>
        <xsl:otherwise> <xsl:value-of select="node6"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell> 
     <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='(node7="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node7"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node8="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node8"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node9="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node9"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node10="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node10"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell> 
     <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='(node11="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node11"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
     <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='(node12="null")'></xsl:when>
         <xsl:otherwise><xsl:value-of select="node12"/></xsl:otherwise>
          </xsl:choose>
         </fo:block> 
     </fo:table-cell>
    </fo:table-row>

------------------------------------------------


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


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



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


Current Thread