【问题标题】:Getting an element value based on some conditions in XSLT根据 XSLT 中的某些条件获取元素值
【发布时间】:2019-02-11 14:54:36
【问题描述】:

下面是我的源 XML,我需要在其中获取 doc_id,其中 doc_tag 等于“可交付”。在下面的示例中,我需要 doc_id 为 123654789,因为 doc_tag 等于可交付成果,我尝试了各种 X 路径,但我无法准确地将 doc_tag 定位为可交付成果

非常感谢任何帮助。

谢谢
文克

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <document>
        <doc_id>321654987</doc_id>
        <doc_tag>Log</doc_tag>
    </document>
    <document>
        <doc_id>123654789</doc_id>
        <doc_tag>deliverable</doc_tag>
    </document>
    <document>
        <doc_id>325698741</doc_id>
        <doc_tag>Log2</doc_tag>
    </document>
    <document>
        <doc_id>369852147</doc_id>
        <doc_tag>nondeliverable</doc_tag>
    </document>
</root>

【问题讨论】:

  • 您能展示一下您目前尝试过的任何 xpath 表达式吗?谢谢!
  • //document[doc_tag="deliverable"]/doc_id/text() 选择 doc_id 值
  • 嗨蒂姆,我试过这个 xpath
  • 您能否编辑您的问题以包含该模板,因为代码在 cmets 中难以阅读。谢谢!

标签: xml xslt xslt-2.0 xslt-grouping


【解决方案1】:

如果你想在与文档节点匹配的模板中获取值

<xsl:template match="/"> 
   <xsl:value-of select="root/document[doc_tag='deliverable']/doc_id" />
</xsl:template>

方括号表示应过滤所选document 元素的条件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多