开发者

xpath from string

I'm trying to do xpath expression from string literal. I create my xpath from some variables so I can't precalculate them. 开发者_JAVA技巧I end up with sth like this:

count(concat("//sales:", "$variable", "Available"))

and it results in an error:

Can not convert #STRING to a NodeList!

I think it would suffice if I could somehow evaluate() the result of concat so it would become the actual NodeList. Is there an appropriate function to do this?

I'm doing this text manipulation in Apache Camel, but it's not so important IMO.

EDITED:

To be more precise: Apache Camel works as a pipeline, XMLs go through it and you can process those XMLs in some ways - like impose some rules based on XMLs content or structure. That is why I need this to be dynamic.

My situation looks like this:

  1. look at the xml and get the content of element operationName
  2. search in some other document for an element that is constructed from the lower-cased operationName and string literal 'Available'

So if my operationName is FOOBAR, than I want to check for the existence of node //sales:foobarAvailable


Evaluation of dynamically generated XPath expressions is not supported in XSLT/XPath until version 3.0, which are in their early WD (working draft) status at present.

If more is known about the XPath expression, then usually some solution can be designed.

Therefore, if you describe your problem in more detail, the chances are good that someone would be able to help.

UPDATE: There is this new information from the OP:

So if my operationName is FOOBAR, than I want to check for the existence of node //sales:foobarAvailable

This is easy to do:

Use:

//sales:*[local-name()
         =
          concat(translate(operationName, $vUpper, $vLower), 'Available')
         ]

where $vUpper and $vLower are defined as (can be substituted by):

'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

and

'abcdefghijklmnopqrstuvwxyz'


If your XSLT processor doesn't have an xx:evaluate extension (and you can't switch to one that does), then another technique that can be useful in some situations is to write a meta-stylesheet -- a stylesheet that creates or modifies another stylesheet. You then run these two in some kind of pipeline.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜