param containing nodes and for-each

  • Thread starter Jean-Christophe Michel
  • Start date
J

Jean-Christophe Michel

Hi,

I have a stylesheet with an accumulator like this

<xsl:param 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" />
</xsl:param>

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.
 
M

Marrow

Hi,
I have a stylesheet with an accumulator like this

<xsl:param 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" />
</xsl:param>
[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
 
J

Jean-Christophe Michel

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


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 :(
 
M

Marrow

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
 
J

Jean-Christophe Michel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top