天天看點

SAP ABAP實用技巧介紹系列之 ABAP XSLT 使用attribute增加新的屬性

用于測試的xml:

Empire Burlesque

Bob Dylan

USA

Columbia

10.90

1985

Hide your heart

Bonnie Tyler

UK

CBS Records

9.90

1988

對于比對到的第一個node,如果其node name不為空,則輸出一個新的名為pii的node,并且用xsl:attribute給該node assign一個新的attribute,name為node_value, 其value等于比對的node name。

[外鍊圖檔轉存失敗(img-COxHAZPu-1562254210945)(https://user-images.githubusercontent.com/5669954/27301799-d70991ca-5534-11e7-85db-3431a69282b4.png)]

輸出:

[外鍊圖檔轉存失敗(img-qs3m2J4W-1562254210946)(https://user-images.githubusercontent.com/5669954/27301804-d71e90e8-5534-11e7-9e36-4813b923cccd.png)]

若再line22後加上一行 ,則能将輸入的xml也copy到輸出中:

[外鍊圖檔轉存失敗(img-AYcIOuAn-1562254210947)(https://user-images.githubusercontent.com/5669954/27301802-d70bdf66-5534-11e7-80da-d5964f809082.png)]

将line7替換成select="node()|*"能達到同樣效果。

select="@*"則比對xml中所有的unique attribute:

[外鍊圖檔轉存失敗(img-HFVZTAam-1562254210949)(https://user-images.githubusercontent.com/5669954/27301800-d70a8260-5534-11e7-8f81-e36c21d635f3.png)]

例如xml檔案中catalog node 的attribute priority值為very high:

[外鍊圖檔轉存失敗(img-EEn8eMdh-1562254210951)(https://user-images.githubusercontent.com/5669954/27301803-d70d567a-5534-11e7-9b62-be01792f956b.png)]

比對結果:

[外鍊圖檔轉存失敗(img-HkqKC1GC-1562254210951)(https://user-images.githubusercontent.com/5669954/27301801-d70aa3bc-5534-11e7-9185-ed31f1076d54.png)]