[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

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


> 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]">
       <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>
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.

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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.