【发布时间】:2015-11-04 16:08:32
【问题描述】:
我没有在类似的帖子中找到解决方案,所以我希望有人可以帮助我。我的 XML 如下(摘录):
<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 执行此操作。
我发现评估返回一个字符串,而不是一个节点集,我可能需要有多个结果。哪个 XPath 会返回一个 NODESET?
感谢您的帮助!
【问题讨论】: