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

时间:2022-06-25
本文章向大家介绍SAP ABAP实用技巧介绍系列之 ABAP XSLT copy keyword,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Created by Jerry Wang on Jun 30, 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>

下列xslt将只会输出h2的My CD Collection,因为sub template 匹配之后没有任何实现:

但是如果sub template未匹配成功,例如指定了一个错误的path:

添加copy keyword可以让匹配的node加入到输出中:

<xsl:template match="/catalog/cd">
<p>hel</p>
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>
</xsl:stylesheet>

输出:

删除copy keyword只保留apply-templates效果相同:

使用copy将每个cd node重复输出三次: