开发者

How can I use xsl stylesheet parameters to set a node name in XPATH expression?

开发者 https://www.devze.com 2022-12-31 23:08 出处:网络
I have the following XPATH expression: select=\"catalog/product/$category_name = $category_value\" In the given example $category_name and $category_value are the XSL parameters that I receive from

I have the following XPATH expression:

select="catalog/product/$category_name = $category_value"

In the given example $category_name and $category_value are the XSL parameters that I receive from my servlet and I want to use them in XSL to filter the XML result based on category and its value.However, for some reason when,say, $category_name parameter equals 'price' attribute of the 'product' parent node and $开发者_运维知识库category_value equals 40, the given expression does not return any result at all! Logically, the expression should be transformed to something like select="catalog/product/price = 40"....I guess there is some problem with specifying the node name which is the category in my case. Can anyone suggest the way to get around this problem?


You probably want:

catalog/product/*[name()=$category_name] [. = $category_value]


For variable xpath expressions, use dynamic xpath. See Is it possible to use a Dynamic xPath expression in a xslt style sheet?

0

精彩评论

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