zl程序教程

您现在的位置是:首页 >  其他

当前栏目

SAP ABAP实用技巧介绍系列之 ABAP XSLT match keyword

SAP 介绍 系列 ABAP 实用技巧 match keyword XSLT
2023-09-14 09:02:51 时间

Created by Jerry Wang, last modified on Jun 26, 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>

在tcode strans创建的xslt program:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
  <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

match = “/” 意为匹配整个xml document:
测试输出:
clipboard1
输出结果来自xslt里manual 指定的h2 tag 以及匹配的整个xml document中每个节点的value,但不包含节点名称本身。
如果把match = “/”替换成 match = “title”:
clipboard2
输出如下, 因此此时有两个匹配的title node。
clipboard3

match=“catalog”: 效果如/
match=“cd”: 效果如match = “title”
match=“artist”: 找不到匹配的document,输出为空:
clipboard4
但如果先匹配整个document,再匹配artist node则可成功:
clipboard5
输出如下:
clipboard6

match="/catalog/cd": 输出同match=“cd”
match="/catalog/cd/title": 输出同上
match="/catalog/cd/artist": 输出为空
match=“artist[parent::cd]”>: 输出为空
输入如下:
[外链图片转存失败(img-U8zlk8Ac-1562210924325)(https://user-images.githubusercontent.com/5669954/27290940-0274646e-550f-11e7-9d3c-f2417d434d58.png)]
输出:
clipboard8
match="*":
每个节点都会生成一个h2 node:
clipboard9