[Newbie question] XSL select with parameter isn't working w/ fullXPATH expression

W

Werner Rudolf

Hello,
this simple example below is working w/ Cocoon:
URL: http://localhost:8888/c2/systems.html?xpa=Active
XSL: <xsl:for-each select="/systems/system[status=$xpa]">

For a simple application, it would be very usefull, if I could pass full
XPATH expressions with the URL to gain better flexibility for queries.
Something like:
URL:
http://localhost:8888/c2/systems.html?xpa=/systems/system[status=Active]
XSL: <xsl:for-each select="$xpa">
I just couldn't get this running.

Passing parameters is not standard XSL, I know, but it seems to be
rather a XSL issue than an Cocoon issue, isn't it?


Many thanks and best regards,
Werner
 
D

David Carlisle

Werner Rudolf said:
Hello,
this simple example below is working w/ Cocoon:
URL: http://localhost:8888/c2/systems.html?xpa=Active
XSL: <xsl:for-each select="/systems/system[status=$xpa]">

For a simple application, it would be very usefull, if I could pass full
XPATH expressions with the URL to gain better flexibility for queries.
Something like:
URL:
http://localhost:8888/c2/systems.html?xpa=/systems/system[status=Active]
XSL: <xsl:for-each select="$xpa">
I just couldn't get this running.

Passing parameters is not standard XSL, I know, but it seems to be
rather a XSL issue than an Cocoon issue, isn't it?

at least on the xsl side, you'll need to make sure that $xpa is a node
set and not a string. If you pass in the string
'/systems/system[status=Active]'
then
<xsl:for-each select="$xpa">
is
<xsl:for-each select="'/systems/system[status=Active]'">
which is a fatal error.

Most API's to XSLT engines (other than the command line) allow you to
pass in a node set, that is you need to execute the XPath outside XSLT
and then pass in the resulting node set as the parameter xpa of the
stylesheet. Not sure how one would set that up in cocoon though

alternatively you can pass in a string (which cocoon will do for you)
see use-request-parametersin
http://cocoon.apache.org/2.1/userdocs/transformers/xslt-transformer.html
and then use an extension function in the stylesheet to evaluate that
string as an xpath.
saxon has saxon:evaluate() I think xalan has something similar.

David
 
W

Werner Rudolf

Hello David,
wow, that has been a very fast answer!
Many thanks for the hint with the evaluate function, I couldn't load it
so far, got "No resolution for Xalan prefix" (or something like that),
but I'll try again!

Many thanks and best regards,
Werner

David said:
Hello,
this simple example below is working w/ Cocoon:
URL: http://localhost:8888/c2/systems.html?xpa=Active
XSL: <xsl:for-each select="/systems/system[status=$xpa]">

For a simple application, it would be very usefull, if I could pass full
XPATH expressions with the URL to gain better flexibility for queries.
Something like:
URL:
http://localhost:8888/c2/systems.html?xpa=/systems/system[status=Active]
XSL: <xsl:for-each select="$xpa">
I just couldn't get this running.

Passing parameters is not standard XSL, I know, but it seems to be
rather a XSL issue than an Cocoon issue, isn't it?


at least on the xsl side, you'll need to make sure that $xpa is a node
set and not a string. If you pass in the string
'/systems/system[status=Active]'
then
<xsl:for-each select="$xpa">
is
<xsl:for-each select="'/systems/system[status=Active]'">
which is a fatal error.

Most API's to XSLT engines (other than the command line) allow you to
pass in a node set, that is you need to execute the XPath outside XSLT
and then pass in the resulting node set as the parameter xpa of the
stylesheet. Not sure how one would set that up in cocoon though

alternatively you can pass in a string (which cocoon will do for you)
see use-request-parametersin
http://cocoon.apache.org/2.1/userdocs/transformers/xslt-transformer.html
and then use an extension function in the stylesheet to evaluate that
string as an xpath.
saxon has saxon:evaluate() I think xalan has something similar.

David
 

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,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top