【问题标题】:XSLT / XML select value by nameXSLT / XML 按名称选择值
【发布时间】:2019-12-13 09:51:50
【问题描述】:

XSLT 的新手,但有以下场景。我试图在我的XSLT 中获取'ABCDE' 的 GroupControlNumber 值,但不知道如何按名称调用它。

这是 XML 的 sn-p

<Transactions>
  <Transaction Status="Accepted">
    <IdentifierName>TransactionControlNumber</IdentifierName>
    <TransactionNumber>0001</TransactionNumber>
    <Identifiers>
      <Envelope IdentifierName="ControlNumber" IdentifierValue="12345" />
      <Envelope IdentifierName="GroupControlNumber" IdentifierValue="ABCDE" />
      <Envelope IdentifierName="OriginatorId" IdentifierValue="!@#$%" />
    </Identifiers>
  </Transaction>
</Transactions>

这是我目前在 XSLT 方面的成果

<xsl:value-of select="../../../../Identifiers/Envelope/@IdentifierValue"/>

但这给了我所有三个标识符值。我明白为什么我得到所有 3 个,只是想过滤它。

Output
12345 ABCDE !@#$%
Desired output
ABCDE

谢谢!!

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    这是你的xpath

    //Transactions/Transaction/Identifiers/Envelope[@IdentifierName='GroupControlNumber'][1]/@IdentifierValue
    

    【讨论】:

    • 我不知道你可以通过索引访问!这很棒!谢谢 ϻᴇᴛᴀʟ
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多