This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: for-each over variable problem
- From: Joerg Heinicke <joerg dot heinicke at gmx dot de>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 04 Feb 2002 16:50:07 +0100
- Subject: Re: [xsl] for-each over variable problem
- References: <OF4C5B88B9.6756B362-ONC2256B56.004AD167@e-know.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Your problem is well-known. It's because of two different data-types in
XSLT: nodeset and result tree fragment. In your variable $Modules you
are creating a RTF. For a nodeset you have to convert this via processor
specific extension functions. I don't know the extensions of Sablotron,
but Saxon, Xalan and MSXML have them. An example:
<xsl:stylesheet version="1.0" xmlns:xsl=".."
xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan">
<xsl:variable name="Modules">
<module>InternalCS</module>
<module>FileCS</module>
</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="nodeset($Modules)/module">
<!-- do anything -->
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
You have to do something like this in your event-template.
Regards,
Joerg
Jakub.Valenta@Deio.net wrote:
> Hi all,
> I am trying to iterate over a variable using for-each, and I am getting
> errors with majority of parsers :-(.
> The only one working is Sablotron (I am using cooktop, to test which engine
> works).
>
> the style sheet looks like
>
> <xsl:stylesheet version="1.0" xmlns:xsl
> ="http://www.w3.org/1999/XSL/Transform">
>
>
> <!-- VARIABLE -->
>
> <xsl:variable name="Modules">
> <module>InternalCS</module>
> <module>FileCS</module>
> </xsl:variable>
>
> <xsl:template match="wrapper">
> <xsl:for-each select="event">
> <xsl:call-template name="event" />
> </xsl:for-each>
> </xsl:template>
>
>
> <!-- THE PROBLEMATIC FOR-EACH -->
>
> <xsl:template name="event">
> <xsl:for-each select="$Modules/module">module</xsl:for-each>
> </xsl:template>
>
> </xsl:stylesheet>
>
> and the input is
>
> <wrapper>
> <event>1</event>
> <event>2</event>
> <event>3</event>
> ..
> </wrapper>
>
> In Michael Kay's book is example like this on p.343, but id does not work
> here. Any idea why?
>
> I usually get error like " Reference to variable or parameter 'Modules'
> must evaluate to a node list."
>
> br,
>
> Jakub
--
System Development
VIRBUS AG
Fon +49(0)341-979-7411
Fax +49(0)341-979-7409
joerg.heinicke@virbus.de
www.virbus.de
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list