Re: [xsl] string parameter to node-set?

Subject: Re: [xsl] string parameter to node-set?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 3 Jan 2003 17:09:40 GMT
> I suppose this is because the parameter is of type string, and the 
> select attribute requires a node set. How do I solve this?

this is a FAQ.
Some systems (saxon, and xalan for example) have an evaluate extension
that allows a string to be evaluated as an X{ath expression, however
there are more poratble alternatives.

In simple cases you can pass in a string used to make up
the expression, so instead of

  para-xpath=/root/data[@id='whatever'
...
 <xsl:apply-templates select="$para-xpath"/>

  para-id=whatever

 <xsl:apply-templates select="/root/data[@id=$para-id]"/>


Otherwise if you are calling XSLT from some API rather than the command
line it is usually possible to make the parameter have a value being the
node set itself rather than an Xpath taht selects the node set.
Typically you use some Xpath interface to a DOM to select teh node set
and then pass that in as the parameter, then your

<xsl:apply-templates select="$para-xpath"/>

would work.

> The key problem is that I need to transform a subset of a larger XML 
> stream, where the subset is defined through an XPath expression and all 
> this must happen within XSL in order to avoid cross-domain security 
> constrains in JavaScript.

hmm so the last possibility may not be avaolable to you.


>  Any recommendations welcome.

You could ask the XSLT WG to reconsider adding evaluate to xpath 2....

Or you can have a two pass approach, take the xpath expression from teh
source and generate a stylesheet that uses that expression, then run teh
generated stylesheet.

David



________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread