Re: Re[2]: [xsl] not standart table in stylesheet, need advise

Subject: Re: Re[2]: [xsl] not standart table in stylesheet, need advise
From: Kevin Jones <kjones@xxxxxxxxxxx>
Date: Fri, 28 Feb 2003 13:52:22 +0000
On Friday 28 February 2003 11:45, Andrey Solonchuk wrote:

Cut...

>
> But i have question with variables
>
> <xsl:variable name="flag1" select="list[@flag=2]"/>
> <xsl:variable name="flag2" select="list[@flag=1]"/>
>
> how I can write xsl:for-each on the longest nodelist
>
> I tried next, but it give me an error
> Can not convert #RTREEFRAG to a Nodelist
>
>  <xsl:variable name="loop">
>                 <xsl:choose>
>                    <xsl:when test="count($flag1) > count($flag2)">
>                       <xsl:value-of select="$flag1"/>
>                    </xsl:when>
>                    <xsl:otherwise>
>                       <xsl:value-of select="$flag2"/>
>                    </xsl:otherwise>
>                 </xsl:choose
>   </xsl:variable>
>   <xsl:for-each select="$loop"> ....

To get rid of the error you need to use a nodeset() extention function. 
Something like this should work,

	<xsl:for-each select="xalan:nodeset($loop)">

The problem is that 'loop' is a result tree fragment (RTF) which is different 
sort of data type than a nodeset (what you get from a select="..."). In XSLT 
1.0 you can't convert from a RTF to a nodeset but most processors allow it 
via a nodeset() extention function.

Having said that I don't think this is quite what you want as 'loop' is going 
to contain the string value of the first node, this is what 'value-of' does. 
You could replace 'value-of' by 'copy-of' to actually copy the nodes but that 
can be slow if you have large documents.  

The only other solution I can think of is to do somthing like this,

<xsl:for-each select="/root/list">
   <xsl:variable name="i" select="position()"/>
   <xsl:if test="$flag1[position()==$i] or $flag2[position()==$i]">
     <tr>
       <th><xsl:value-of select="$flag1[position()=$i]/code-pMT"/></th>
       <th><xsl:value-of select="$flag1[position()=$i]/sname"/></th>
       <th><xsl:value-of select="$flag1[position()=$i]/sum-amt"/></th>
       <th><xsl:value-of select="$flag1[position()=$i]/days"/></th>
       <th><xsl:value-of select="$flag2[position()=$i]/code-pMT"/></th>
       <th><xsl:value-of select="$flag2[position()=$i]/sname"/></th>
       <th><xsl:value-of select="$flag2[position()=$i]/sum-amt"/></th>
    </tr>
   </xsl:if>
</xsl:for-each>
  
This will loop more than you need but only output data for rows where you have 
data to be shown. This eliminates the need for doing a length test at the 
cost of some redundant computation.
 
Kev.


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


Current Thread