Xml 为什么这个xpath返回一个空节点集?
以下是XML:Xml 为什么这个xpath返回一个空节点集?,xml,xslt,xpath,Xml,Xslt,Xpath,以下是XML: <recordTarget> <patientRole> <patient> <religiousAffiliationCode code="1013" displayName="Christian (non-Catholic, non-specific)" codeSystem="2.16.840.1.113883.5.1076" codeSystemName="HL7
<recordTarget>
<patientRole>
<patient>
<religiousAffiliationCode code="1013" displayName="Christian (non-Catholic, non-specific)" codeSystem="2.16.840.1.113883.5.1076" codeSystemName="HL7 Religious Affiliation"/>
</patient>
</patientRole>
</recordTarget>
这是我的xpath语句(n1是名称空间)
根据XML评估XPath的结果取决于您没有告诉我们的因素 这取决于
- 当前上下文,因为它是相对的 XPath
名称空间前缀的定义 在XML和承载 XPath。看n1
,recordTarget
的命名空间, 等等,如果没有看到它们的全部遗产就无法确定patientRole
宗教事务代码的拼写
(顺便说一句,防止路径表达式中拼写错误的唯一真正防御措施是使用XSLT 2.0中的模式感知功能,如果您正确利用这些功能,就可以在编译时检查路径对模式是否有意义。这在使用诸如HL7之类的词汇表时尤其重要,其中名称为10我只包含了少量的XML,但当前的上下文是正确的,名称空间n1已经定义。Michael Kay有敏锐的眼睛。这是一个拼写错误。我的朋友,你们有敏锐的眼睛。谢谢!
<xsl:variable name="religion" select="n1:recordTarget/n1:patientRole/n1:patient/n1:religiousAffilliationCode/@displayName"/>