xpath-1.0

How to pass variable parameter into XPath expression?

China☆狼群 提交于 2019-11-26 15:33:42
I want to pass a parameter into an XPath expression. (//a/b/c[x=?],myParamForXAttribute) Can I do this with XPath 1.0 ? (I tried string-join but it is not there in XPath 1.0) Then how can I do this ? My XML looks like <a> <b> <c> <x>val1</x> <y>abc</y> </c> <c> <x>val2</x> <y>abcd</y> </c> </b> </a> I want to get <y> element value where x element value is val1 I tried //a/b/c[x='val1']/y but it did not work. Given that you're using the Axiom XPath library, which in turn uses Jaxen, you'll need to follow the following three steps to do this in a thoroughly robust manner: Create a

Encoding XPath Expressions with both single and double quotes

こ雲淡風輕ζ 提交于 2019-11-26 11:12:15
问题 XPath (v1) contains no way to encode expressions. If you only have single OR double quotes then you can use expressions such as //review[@name=\"Bob\'s Pizza\"] //review[@name=\'\"Pizza\" Pam\'] But if you have BOTH e.g [Fred\'s \"Fancy Pizza\"] then you have to use something like this Escaping Strings in XPath (C++) to generate //review[@name=Concat(\"Fred\'s \",\'\"Fancy Pizza\"\')] Anyone have a function in c# to do this? Some links that are close Use the MVP.XML library and XPathVariable

How can I use XPath to find the minimum value of an attribute in a set of elements?

和自甴很熟 提交于 2019-11-26 05:30:38
问题 If I have XML like: <foo> <bar id=\"1\" score=\"192\" /> <bar id=\"2\" score=\"227\" /> <bar id=\"3\" score=\"105\" /> ... </foo> Can I use XPath to find the minimum and maximum values of score ? Edit : The tool i\'m using (Andariel ant tasks) doesn\'t support the XPath 2.0 solution. 回答1: Here's a slightly shorter solution. Maximum: /foo/bar/@score[not(. < ../../bar/@score)][1] Minimum: /foo/bar/@score[not(. > ../../bar/@score)][1] I've edited the predicate so that it's applicable to any

XSLT string replace

微笑、不失礼 提交于 2019-11-26 00:25:33
问题 I don\'t really know XSL but I need to fix this code, I have reduced it to make it simpler. I am getting this error Invalid XSLT/XPath function on this line <xsl:variable name=\"text\" select=\"replace($text,\'a\',\'b\')\"/> This is the XSL <xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:inm=\"http://www.inmagic.com/webpublisher/query\" version=\"1.0\"> <xsl:output method=\"text\" encoding=\"UTF-8\" /> <xsl:preserve-space elements=\"*\" /> <xsl:template match=\"text()