将前缀绑定注册到相应的命名空间后,使用:
/*/s:Body
/s:About_ServiceResponse
/s:About_ServiceResult
/a:businessServiceVersionStructureField
/a:BusinessServiceVersionStructureType
/a:businessServiceVersionNameField
/text()
当针对以下 XML 文档评估此 XPath 表达式时(提供的格式严重错误,我不得不花费大量时间使其格式正确):
<s:Envelope xmlns:s="http://...">
<s:Body>
<About_ServiceResponse xmlns="http://...">
<About_ServiceResult xmlns:a="http://">
<a:businessServiceVersionStructureField>
<a:BusinessServiceVersionStructureType>
<a:businessServiceDBVersionNameField>V001</a:businessServiceDBVersionNameField>
<a:businessServiceVersionNameField>Some Service^V100</a:businessServiceVersionNameField>
</a:BusinessServiceVersionStructureType>
</a:businessServiceVersionStructureField>
</About_ServiceResult>
</About_ServiceResponse>
</s:Body>
</s:Envelope>
正好选择了想要的文本节点:
Some Service^V100
如果要选择作为此文本节点父级的元素,请使用:
/*/s:Body
/s:About_ServiceResponse
/s:About_ServiceResult
/a:businessServiceVersionStructureField
/a:BusinessServiceVersionStructureType
/a:businessServiceVersionNameField
基于 XSLT 的验证:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://..." xmlns:a="http://">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select=
"/*/s:Body
/s:About_ServiceResponse
/s:About_ServiceResult
/a:businessServiceVersionStructureField
/a:BusinessServiceVersionStructureType
/a:businessServiceVersionNameField
/text()
"/>
=======
<xsl:copy-of select=
"/*/s:Body
/s:About_ServiceResponse
/s:About_ServiceResult
/a:businessServiceVersionStructureField
/a:BusinessServiceVersionStructureType
/a:businessServiceVersionNameField
"/>
</xsl:template>
</xsl:stylesheet>
当此转换应用于同一个 XML 文档(如上)时,将输出所选节点(使用“=======”作为分隔符):
Some Service^V100
=======
<a:businessServiceVersionNameField xmlns:a="http://" xmlns="http://..." xmlns:s="http://...">Some Service^V100</a:businessServiceVersionNameField>