Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > param containing nodes and for-each

Reply
Thread Tools

param containing nodes and for-each

 
 
Jean-Christophe Michel
Guest
Posts: n/a
 
      07-12-2003
Hi,

I have a stylesheet with an accumulator like this

<xslaram name="new-x">
<xsl:for-each select="anode">
<mynode>
<xsl:attribute name="attr">
<xsl:value select="anode/atag" />
</xsl:attribute>
</mynode>
</xsl:for-each>
<xsl:copy-of select="$x" />
</xslaram>

if I test with
<print-x>
<xsl:copy-of select="$new-x" />
</print-x>

i get the expected output:

<print-x>
<mynode attr="foo1" />
<mynode attr="foo2" />
<mynode attr="foo3" />
</print-x>

but later in the same template

count($new-x) returns 1

and

<xsl:for-each select="$new-x">
<xsl-value-of select="@attr" />
</xsl:for-each>

returns an empty result...

Some tips ?

I use xsltproc under debian sid.
 
Reply With Quote
 
 
 
 
Marrow
Guest
Posts: n/a
 
      07-13-2003
Hi,

> I have a stylesheet with an accumulator like this
>
> <xslaram name="new-x">
> <xsl:for-each select="anode">
> <mynode>
> <xsl:attribute name="attr">
> <xsl:value select="anode/atag" />
> </xsl:attribute>
> </mynode>
> </xsl:for-each>
> <xsl:copy-of select="$x" />
> </xslaram>
> [snip]
> but later in the same template
>
> count($new-x) returns 1


With most transformation engines that would actually cause an error -
because $new-x contains an RTF (result tree fragment) but the count()
function takes a node-set as an argument. So it looks like your
transformation engine, xsltproc, is doing automatic RTF to node-set
conversions.

Assuming that it is the case (that automatic RTF to node-set conversions are
occuring) then a result of 1 would be correct. This is because an RTF, like
an XML document, has a single root node.

Therefore, if you try...
<xsl:value-of select="count($new-x/*)"/>
or...
<xsl:value-of select="count($new-x/mynode)"/>

you will most likely get the result you expect.

Also...

> <xsl:for-each select="$new-x">
> <xsl-value-of select="@attr" />
> </xsl:for-each>


You probably want...
<xsl:for-each select="$new-x/*">
or...

<xsl:for-each select="$new-x/mynode">

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


"Jean-Christophe Michel" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hi,
>
> I have a stylesheet with an accumulator like this
>
> <xslaram name="new-x">
> <xsl:for-each select="anode">
> <mynode>
> <xsl:attribute name="attr">
> <xsl:value select="anode/atag" />
> </xsl:attribute>
> </mynode>
> </xsl:for-each>
> <xsl:copy-of select="$x" />
> </xslaram>
>
> if I test with
> <print-x>
> <xsl:copy-of select="$new-x" />
> </print-x>
>
> i get the expected output:
>
> <print-x>
> <mynode attr="foo1" />
> <mynode attr="foo2" />
> <mynode attr="foo3" />
> </print-x>
>
> but later in the same template
>
> count($new-x) returns 1
>
> and
>
> <xsl:for-each select="$new-x">
> <xsl-value-of select="@attr" />
> </xsl:for-each>
>
> returns an empty result...
>
> Some tips ?
>
> I use xsltproc under debian sid.



 
Reply With Quote
 
 
 
 
Jean-Christophe Michel
Guest
Posts: n/a
 
      07-13-2003
On Sun, 13 Jul 2003 08:27:57 +0100, Marrow wrote:
> With most transformation engines that would actually cause an error -
> because $new-x contains an RTF (result tree fragment) but the count()
> function takes a node-set as an argument. So it looks like your
> transformation engine, xsltproc, is doing automatic RTF to node-set
> conversions.
>
> Assuming that it is the case (that automatic RTF to node-set conversions
> are occuring) then a result of 1 would be correct. This is because an
> RTF, like an XML document, has a single root node.
>
> Therefore, if you try...
> <xsl:value-of select="count($new-x/*)"/>
> or...
> <xsl:value-of select="count($new-x/mynode)"/>
>
> you will most likely get the result you expect.


No... i thought if it, but i only get

XPath error Invalid type in count($new-x/*)
or
XPath error Invalid type in count($new-x/mynode)

>
> Also...
>
>> <xsl:for-each select="$new-x">
>> <xsl-value-of select="@attr" />
>> </xsl:for-each>

>
> You probably want...
> <xsl:for-each select="$new-x/*">
> or...
>
> <xsl:for-each select="$new-x/mynode">


I tried all this; even a
<xsl:call-template name="another" select="$new-x" />
or
<xsl:apply-templates select="$new-x" />
with
<xsl:template match="mynode" >

but in the 'another' template i cannot do more.

I think it's very strange to be able to place some xml into a param but
not being able to parse it later as real xml
said differently, this distinction between node-set and result tree
fragment seems to me like weak point of xsl; i cannot see its advantage.

I'll have to output the param content in a temp file then call a second
xsl
 
Reply With Quote
 
Marrow
Guest
Posts: n/a
 
      07-13-2003
Hi,

In that case your transformatin engine is not, after all, performing
automatic RTF to node-set conversions. In which case...
<xsl:value-of select="count($new-x)"/>
should cause an error.

Anyway, as you are dealing with an RTF...

In most transformation engines they supply an extension function (e.g.
xxx:node-set() or xxx:nodeset() etc.) that allow you to convert an RTF to a
node-set. You will have to check the documentation for your transformation
engine.

> I think it's very strange to be able to place some xml into a param but
> not being able to parse it later as real xml
> said differently, this distinction between node-set and result tree
> fragment seems to me like weak point of xsl; i cannot see its advantage.


Probably the reason that the whole concept of RTFs has gone in XSLT 2.0

Cheers
Marrow

"Jean-Christophe Michel" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Sun, 13 Jul 2003 08:27:57 +0100, Marrow wrote:
> > With most transformation engines that would actually cause an error -
> > because $new-x contains an RTF (result tree fragment) but the count()
> > function takes a node-set as an argument. So it looks like your
> > transformation engine, xsltproc, is doing automatic RTF to node-set
> > conversions.
> >
> > Assuming that it is the case (that automatic RTF to node-set conversions
> > are occuring) then a result of 1 would be correct. This is because an
> > RTF, like an XML document, has a single root node.
> >
> > Therefore, if you try...
> > <xsl:value-of select="count($new-x/*)"/>
> > or...
> > <xsl:value-of select="count($new-x/mynode)"/>
> >
> > you will most likely get the result you expect.

>
> No... i thought if it, but i only get
>
> XPath error Invalid type in count($new-x/*)
> or
> XPath error Invalid type in count($new-x/mynode)
>
> >
> > Also...
> >
> >> <xsl:for-each select="$new-x">
> >> <xsl-value-of select="@attr" />
> >> </xsl:for-each>

> >
> > You probably want...
> > <xsl:for-each select="$new-x/*">
> > or...
> >
> > <xsl:for-each select="$new-x/mynode">

>
> I tried all this; even a
> <xsl:call-template name="another" select="$new-x" />
> or
> <xsl:apply-templates select="$new-x" />
> with
> <xsl:template match="mynode" >
>
> but in the 'another' template i cannot do more.
>
> I think it's very strange to be able to place some xml into a param but
> not being able to parse it later as real xml
> said differently, this distinction between node-set and result tree
> fragment seems to me like weak point of xsl; i cannot see its advantage.
>
> I'll have to output the param content in a temp file then call a second
> xsl



 
Reply With Quote
 
Jean-Christophe Michel
Guest
Posts: n/a
 
      07-13-2003
On Sun, 13 Jul 2003 10:03:16 +0100, Marrow wrote:

> Hi,
>
> In that case your transformatin engine is not, after all, performing
> automatic RTF to node-set conversions. In which case...
> <xsl:value-of select="count($new-x)"/>
> should cause an error.


Strange, but it doesn't

> Anyway, as you are dealing with an RTF...
>
> In most transformation engines they supply an extension function (e.g.
> xxx:node-set() or xxx:nodeset() etc.) that allow you to convert an RTF to
> a node-set. You will have to check the documentation for your
> transformation engine.


It' xsltproc, based on libxslt (for Gnome), but no mention of this...

Thanks, i could use it with the name space
xmlls:exslt="http://exslt.org/common"

then call exslt:node-set($myparam)
in all expressions.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML::Template->param() : You gave me an odd number of parameters to param()! Dave Perl Misc 5 04-26-2011 02:44 AM
Overload by deriv class param; call w base class param ectoplasm C++ 12 07-28-2005 08:20 AM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
Global xsl:param containing xpath expression string kurt hansen XML 1 09-07-2004 03:54 PM
XSLT: How to replace param name with this param's value ? Geathaa XML 2 07-30-2003 06:48 AM



Advertisments