开发者

Dynamically buiding an XPath query string

I have a chained XSLT 2.0 transformation scenario (using saxon), like this:

- I1.xml is input for T1.xslt, stylesheet which will build T2.xslt

- I2.xml is input for T2.xslt, stylesheet which will output O1.xml

I would like to have an xsl:function (so that it will be available in XPath expressions), let's call it my:f( dataNode, queryString ), which will query dataNode using the supplied query, similar with below:

<xsl:function name="my:f">
       <xsl:param name="dataNode" as="item()*"/>
       <xsl:param name="query" as="xsd:string"/>
             <xsl:sequence select="$dataNode/$query"/>
</xsl:function>

my:f() is stored in a separate file and included only by T2开发者_运维技巧.

my:f() is isolated in a file because depending on configuration, it might call an extension function for performing the query.

my:f() call is, of course, "build" in T1 ( where the XPath queryString is dynamically concatenated ), but it is actually called only in T2.

The only problem that I seem to have .. is how to actually pass the dynamically build queryString from T1 to T2 and then to my:f() as a simple string (as the actual query will be performed by my:f()).

Does anyone have any ideas (and ideally some code) about how to approach this?

Regards


Well if you want to construct and evaluate XPath expressions at run-time then you need to use an extension function like http://www.saxonica.com/documentation/extensions/functions/evaluate.xml: <xsl:sequence select="saxon:evaluate(concat('$p1/', $query), $dataNode)"/>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜