SAP ABAP实用技巧介绍系列之 ABAP XSLT 使用attribute增加新的属性
Created by Jerry Wang on Jul 01, 2014
用于測試的xml:
<catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> </catalog>對于匹配到的第一個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后加上一行 <xsl:copy-of select="./*"/>,則能將輸入的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)]
總結
以上是生活随笔為你收集整理的SAP ABAP实用技巧介绍系列之 ABAP XSLT 使用attribute增加新的属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用linux的zgrep命令在压缩文件
- 下一篇: SAP ABAP实用技巧介绍系列之 在x