0

我是 XSLT 的新手。我有如下 XML 消息:

<Root>
<Payload>
    <SendEmail>
        <customerID>123123</customerID>
        <subscriberID>123123</subscriberID>         
        <MessageDetails>
            <AttributeList>
                <Attribute Name="CcEmailAddress">abc@abc.com</Attribute>
                <Attribute Name="BcccEmailAddress">abc@abc.com</Attribute>
                <Attribute Name="SenderEmailAddress">abc@abc.com</Attribute>
                <Attribute Name="SenderMobileNo">abc@abc.com</Attribute>
                <Content  Name="MobileNo">abc@abc.com</Content>
                <Content  Value="TxnNO">abc@abc.com</Content>
                <ERCo   ercvalue="ERCNO">abc@abc.com</ERCo>
                <Attribute Name="OrderHeader"><![CDATA[" and ends with "]]></Attribute>         
            </AttributeList>
        </MessageDetails>
        <MessageDetails>
            <AttributeList>
                <Attribute Name="CcEmailAddress">abc@abc.com</Attribute>
                <Attribute Name="BcccEmailAddress">abc@abc.com</Attribute>
                <Attribute Name="SenderEmailAddress">abc@abc.com</Attribute>
                <Attribute Name="SenderMobileNo">abc@abc.com</Attribute>
                <Content  Name="MobileNo">abc@abc.com</Content>
                <Content  Value="TxnNO">abc@abc.com</Content>
                <ERCo   ercvalue="ERCNO">abc@abc.com</ERCo>
                <Attribute Name="OrderHeader"><![CDATA[" and ends with "]]></Attribute>         
            </AttributeList>
        </MessageDetails>
    </SendEmail>
    </Payload>
</Root>

以下是我的要求和问题:

  1. 在 AttributeList 标记中,我必须查找具有特定值(例如 CcEmailAddress )的属性“名称”,然后将相应的字段值(实际电子邮件 ID)映射到我的目标标记。我试过 //[@Name='CcEmailAddress'] 因为它出现在我的输入中一次,所以我决定遍历名称为 Name 和值为 CcEmailAddress 的所有属性。但它似乎没有工作。

  2. 我如何确保我的代码选择了特定的事件?在我的情况下 Message details 重复 n-times 。如果我在 for-each 中使用选择,它只会获取第一个出现的值。当循环在第二个“MessageDetails”上时,我想获取其中的值。我如何做到这一点?

  3. 在 AttributeList 中,我持有 "Attribute" 元素和 n-others 。如果我想搜索“内容”元素并找到属性“名称”=MobileNo 的值(MobileNo 可以出现在任何标签下,但我只想要重复的内容下的东西),我该怎么做?

非常感谢你的帮助 。

4

1 回答 1

1
  1. 我认为这里最好的选择是//Attribute[@Name = 'CcEmailAddress']或者包含Attribute[@Name = 'CcEmailAddress']取决于上下文节点的相对路径。

  2. 您可以使用相对 XPath。如果上下文节点是 MessageDetails,那么可以使用路径AttributeList/Attribute[@Name = 'CcEmailAddress']

  3. 与上述类似,如果您只想考虑Content元素值,则可以使用包含Content[@Name = 'MobileNo']. 同样,由于您正在迭代MessageDetails,这可能是AttributeList/Content[@Name = 'MobileNo']

于 2013-03-19T02:16:32.977 回答