[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Executing variable XPath queries in XSLT


Subject: [xsl] Executing variable XPath queries in XSLT
From: "Joseph Fourness" <josephf@xxxxxxxxxxx>
Date: Fri, 22 Jun 2001 08:53:26 -0700

Hello,
 
I have a source document that looks like the following:
<rule>
<expression>%/PageContent/session/userid</expression>
<condition>eq</condition>
<expression>112314</expression>
</rule>
 
As you can see I'm trying to encode rules and logic into an XML file and
by using XSLT evaluate these rules.  The % symbol denotes an XPath
expression that needs to be executed against an XML file.  I'm getting
this as a variable as follows:
 
<xsl:variable name="xpath-query"
select="substring-after(rule/expression[1], '%')"/>
 
And I would like to then execute this query using $xpath-query in a
select statement.  I would like to do this entirely in XSLT using no
extension mechanisms.  I'm wondering if there are any tricks, known ways
to execute these kinds of expressions.  The methods I've explored so far
are:
1) Pipelining, using two XSLTs the first one to pre-process the XSLT and
convert all %expressions into XPath queries.  The second one to execute
this new XSLT (with the XPaths already built-in)  This works fine, but
is quite tricky and I was hoping to do this in one XSLT.
2) Using <msxsl:script> MSXML extension mechanism.  Writing some simple
JavaScript I instantiate the MSXML parser and use it to process the
XPath query and return a result node-set.  This solution works and seems
to have no problems, but it ties me to MSXML and I would prefer to stay
within the realm of standard XSLT (we are precompiling our XSLTs and
find that calling extension mechanisms is a small performance hit.)
 
I've searched the FAQs and the resources on the internet, but to no
avail.  Hopefully there is some cool way to do this.  (It should be
possible, I think, but I can't think of anything off hand...)
 
Thanks for your help, I greatly appreciate it!
 
Joe Fourness

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



Current Thread
Keywords