我还没有发现类似的线程解决方案,所以我希望有人能帮助我。我有XML如下(节选):的XPath CONCAT同级的所有节点匹配
<root>
<identificationInfo>
<MD_DataIdentification>
<descriptiveKeywords>
<MD_Keywords>
<keyword>
<gco:CharacterString>Atmospheric conditions</gco:CharacterString>
</keyword>
<type>
<MD_KeywordTypeCode codeListValue="theme"/>
</type>
</MD_Keywords>
</descriptiveKeywords>
<descriptiveKeywords>
<MD_Keywords>
<keyword>
<gco:CharacterString>Agriculture</gco:CharacterString>
</keyword>
<keyword>
<gco:CharacterString>Biodiversity</gco:CharacterString>
</keyword>
<type>
<MD_KeywordTypeCode codeListValue="socialBenefitArea"/>
</type>
</MD_Keywords>
</descriptiveKeywords>
我想是连接类型和关键字的字符串,所以我获取列表看起来像以下:
theme:Atmospheric conditions
socialBenefitArea:Agriculture
socialBenefitArea:Biodiversity
我尝试了以下解决方案(XPath 1.0或XPath 2.0都可以使用),但始终只有第一个匹配的“主题:大气条件”返回。
for $n in /*/gmd:identificationInfo/*/gmd:descriptiveKeywords/gmd:MD_Keywords return string-join(($n/gmd:type/*/@codeListValue, ':', $n/gmd:keyword/*/text()), '')
/*/gmd:identificationInfo/*/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/concat(*/text(), ':', ../gmd:type/*/@codeListValue)
//gmd:descriptiveKeywords/*/string-join((gmd:type/*/@codeListValue, gmd:keyword/*/text()[1]), ':')
//gmd:descriptiveKeywords/*/gmd:keyword/concat(following-sibling::gmd:type/*/@codeListValue, ':', ./*/text())
如果XPath的看起来是正确的,我在Java中与Saxon-HE 9.x
这样做。
我没查出是评估返回一个字符串,而不是一个NODESET,我可能需要有多个结果。哪个XPath会返回一个NODESET?
感谢您的帮助!