我正在尝试获取值的Xpath,但获取嵌套条件的错误
我试图通过给条件一个唯一的值U003_O100_001T_609644,从多个ViewItem中找到值为1900310的带有谓词的XPath表达式。请看下面的代码 身份证 1900310 亚型 U003\u O100\u 00IT\u 609644 截面类型 释放 我试着写下面的表达式, 查询=/Envelope/Body/GetViewByIdResponse/GetViewByIdResult/Items/ViewItem/Fields/KeyValueOfstringanyType[Value='U003\U O100\U 001T\U 609644']/Value[Key='ID'] 但这并没有给我价值。你能帮忙吗?我正在尝试获取值的Xpath,但获取嵌套条件的错误,xpath,expression,Xpath,Expression,我试图通过给条件一个唯一的值U003_O100_001T_609644,从多个ViewItem中找到值为1900310的带有谓词的XPath表达式。请看下面的代码 身份证 1900310 亚型 U003\u O100\u 00IT\u 609644 截面类型 释放 我试着写下面的表达式, 查询=/Envelope/Body/GetViewByIdResponse/GetViewByIdResult/Items/ViewItem/Fields/KeyValueOfstringa
谢谢选择所需元素的一个XPath表达式是:
/b:ViewItem
/b:Fields
/c:KeyValueOfstringanyType
[c:Key = 'ID']
/c:Value
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b="some:b" xmlns:c="some:c">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select=
"/b:ViewItem
/b:Fields
/c:KeyValueOfstringanyType
[c:Key = 'ID']
/c:Value
"/>
==============
<xsl:copy-of select=
"/*[local-name() = 'ViewItem']
/*[local-name() = 'Fields']
/*[local-name() = 'KeyValueOfstringanyType']
[*[local-name() = 'Key'] = 'ID']
/*[local-name() = 'Value']
"/>
</xsl:template>
</xsl:stylesheet>
<c:Value xmlns:c="some:c" xmlns:b="some:b">1900310 </c:Value>
==============
<c:Value xmlns:c="some:c" xmlns:b="some:b">1900310 </c:Value>
请注意提供的XML文档具有名称空间,任何包含不固定元素名称的XPath表达式都不会选择所需元素,以下形式的表达式除外:
/*[local-name() = 'ViewItem']
/*[local-name() = 'Fields']
/*[local-name() = 'KeyValueOfstringanyType']
[*[local-name() = 'Key'] = 'ID']
/*[local-name() = 'Value']
另外,对于上面的第一个XPath表达式,前缀为“b:”
和“c:”
必须“注册”(阅读XPath引擎的文档,了解如何注册)
基于XSLT的验证:
/b:ViewItem
/b:Fields
/c:KeyValueOfstringanyType
[c:Key = 'ID']
/c:Value
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b="some:b" xmlns:c="some:c">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select=
"/b:ViewItem
/b:Fields
/c:KeyValueOfstringanyType
[c:Key = 'ID']
/c:Value
"/>
==============
<xsl:copy-of select=
"/*[local-name() = 'ViewItem']
/*[local-name() = 'Fields']
/*[local-name() = 'KeyValueOfstringanyType']
[*[local-name() = 'Key'] = 'ID']
/*[local-name() = 'Value']
"/>
</xsl:template>
</xsl:stylesheet>
<c:Value xmlns:c="some:c" xmlns:b="some:b">1900310 </c:Value>
==============
<c:Value xmlns:c="some:c" xmlns:b="some:b">1900310 </c:Value>
==============
当此XSLT转换应用于以下XML文档时(提供的转换已针对严重的格式错误进行了更正):
身份证件
1900310
亚型
U003\u O100\u 00IT\u 609644
截面类型
释放
计算两个XPath表达式,并输出它们选择的节点:
/b:ViewItem
/b:Fields
/c:KeyValueOfstringanyType
[c:Key = 'ID']
/c:Value
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:b="some:b" xmlns:c="some:c">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select=
"/b:ViewItem
/b:Fields
/c:KeyValueOfstringanyType
[c:Key = 'ID']
/c:Value
"/>
==============
<xsl:copy-of select=
"/*[local-name() = 'ViewItem']
/*[local-name() = 'Fields']
/*[local-name() = 'KeyValueOfstringanyType']
[*[local-name() = 'Key'] = 'ID']
/*[local-name() = 'Value']
"/>
</xsl:template>
</xsl:stylesheet>
<c:Value xmlns:c="some:c" xmlns:b="some:b">1900310 </c:Value>
==============
<c:Value xmlns:c="some:c" xmlns:b="some:b">1900310 </c:Value>
1900310
==============
1900310
我使用了以下查询并获得了值query=/s:Envelope/s:Body/GetViewResponse/GetViewResult/b:Items/b:ViewItem/b:Fields/c:KeyValueOfstringanyType/c:value[text()=\{pSpec}\\]/../../../b:Fields/c:KeyValueOfstringanyType/c:Key[text()=\\\\'ID\\]/../c:value/text()现在我正试图找到这个值的位置…:)非常感谢你的帮助。