2013-03-19 122 views
0

XSLT新增功能。我有如下的XML消息:複雜屬性的XSL轉換

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

下面是我的要求和問題:

  1. 在AttributeList中的標籤,我要查找的屬性「姓名」,它具有特定值(比方說CcEmailAddress),然後將相應的字段值(實際的電子郵件ID)映射到我的目標標記。我試過 // [@ Name ='CcEmailAddress'] 由於它在我的輸入中出現一次,我決定遍歷名稱爲Name和值爲CcEmailAddress的所有屬性。但它似乎沒有工作。

  2. 如何確保我的代碼選擇特定的發生?在我的情況下,消息細節重複n次。如果我在for-each中使用select,它只會獲取第一個發生值。當循環在第二個「MessageDetails」時,我想要獲取它們中的值。我如何實現這一目標?

  3. 在AttributeList中,我擁有「Attribute」元素和n個其他元素。如果我想通過「Content」元素進行搜索並找到屬性「Name」= MobileNo(MobileNo可以出現在任何標籤下,但我只想要重複內容下的東西)的值,我該如何做?

非常感謝您的幫助。

+0

請編輯問題並指定轉換的確切想要的結果。 – 2013-03-19 03:48:02

回答

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']