You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Anne Marie O'Brien <An...@nmss.com> on 2002/08/07 00:10:27 UTC
Re: xsl-for-each
Here is an example of doing this that works fine for me (also the latest
release of Xalan):
-----------------------------------------------------------------------------------
<!-- Reduce input to trunk ID and necessary information for the report
-->
<xsl:variable name="trunks">
<xsl:for-each select="//Session">
<xsl:sort select="channelID"/>
<xsl:element name="trunk-info">
<xsl:element name="trunk">
<xsl:value-of select="substring-before(channelID,
'/Chan')"/>
</xsl:element>
<xsl:element name="connect">
<xsl:value-of select="connectTime"/>
</xsl:element>
<xsl:element name="disconnect">
<xsl:value-of select="disconnectTime"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:variable>
-----------------------------------------------------------------------------------
I then use the xalan:nodeset function to further manipulate the variable...
-----------------------------------------------------------------------------------
<!-- distill the trunk IDs to a list of unique trunks for processing
-->
<xsl:variable name="unique-trunks">
<xsl:for-each select="xalan:nodeset($trunks)/trunk-info">
<xsl:if test="not(trunk = following::trunk)">
<xsl:element name="trunk">
<xsl:value-of select="trunk"/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:variable>
-----------------------------------------------------------------------------------
Are you sure that's the problem?
Anne Marie O'Brien
NMS Communications
(508) 271-1104
"Joseph
Kesselman" To: xalan-dev@xml.apache.org
<keshlam@us.ibm.c cc:
om> Subject: Re: xsl-for-each
07/09/2002 09:01
AM
Please respond to
xalan-dev
>Using the latest xalan (don't know about the behaviour in previous
>versions) I cannot wrap an xsl:for-each as a variable e.g. <xsl:variable
>name="test"><xsl:for-each ......etc... ></xsl:for-each></xsl:variable> I
>get a 'cannot convert tree fragment to node-list exception'.
>However, if I put the 'for each' in a template I can wrap the return from
>this template in a variable.
I haven't worked it through in detail, but I _think_ you're getting burned
by a subtle distinction between a Result Tree Fragment and a nodeset
containing the root node of an RTF. The latter can be assigned directly to
a variable; the former can't be.
Xalan does have a nodeset() extension function, which will wrap a nodeset
around values which aren't nodesets (or aren't even nodes)... but I'm not
sure I see a good way to apply it to your case. Doing the call-template may
indeed be the simplest and most portable answer in XSLT 1.0.
XSLT 2.0 allows Temporary Trees (new name for RTFs) to be treated directly
as nodesets, but we can't do that in a fully compliant 1.0 implementation.
______________________________________
Joe Kesselman / IBM Research