473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

param containing nodes and for-each

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.
Jul 20 '05 #1
4 2001
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
"Jean-Christophe Michel" <jc**************@online.fr> wrote in message
news:pa****************************@online.fr... 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.

Jul 20 '05 #2
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 :(
Jul 20 '05 #3
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" <jc**************@online.fr> wrote in message
news:pa****************************@online.fr... 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 :(

Jul 20 '05 #4
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.

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carl Ogawa | last post by:
The following will stop to open test.pl due to using param('userid') and param('pwd'). Is there an alternative way to get data from HTML file to CGI file? I have to do this in the particular...
5
by: ipg | last post by:
I am running into issues passing a parameter (that is a XML string) into a stylesheet and using msxsl:node-set to parse the string. Can someone please explain why. my html: var xsl = new...
3
by: Kevin | last post by:
I know this has probably been discussed many times before (I found answers when I searched yesterday), but I still can't get it to work... I have an attribute @OID that can contain any...
1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
2
by: aman.coe | last post by:
hello all Consider this xml file: <root> <body> <ElementX id="X1" Xproperty="X_Default_Value" /> <ElementX id="X2" /> </body> </root>
0
by: chriscomer | last post by:
I have successfully setup numerous xmlpoke statements within an Nant script but this specific situation I cannot figure out. I am including a section of the xml code I am trying to access and...
2
by: QTR | last post by:
Hello, I discovered a strange XSLT behaviour on Weblo 8.1. Let me explain it (see at the end my example XSLT): I call a template (1) with one parameter (A) which calls another template (2) with...
1
by: Andy | last post by:
Hi, why does with-param fail to send parameters to any templates in a stylesheet that also accepts arguments from the ASP.NET XML control? The argument from the XML control seems to be available...
2
by: junkblog747 | last post by:
What will the expression "/.." in the attribute select="/.." return? I just inherited a huge stylesheet to maintain which has a lot of parameters such as <xsl:param name="myParam"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.