用于测试的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)]