XSLT 1.0 textlist to individual elements and duplicate removal

笑着哭i 提交于 2019-12-02 12:54:34

Here is a sample:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:key name="k1" 
  match="car[not(@body = 'Fastback')]//text"
  use="concat(ancestor::car/@body, '|', .)"/>

<xsl:template match="cars">
  <xsl:copy>
    <xsl:apply-templates select="car[not(@body =  'Fastback')]//text
      [generate-id() = generate-id(key('k1', concat(ancestor::car/@body, '|', .))[1])]"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="text">
  <car type="{ancestor::car/@body}">
    <xsl:value-of select="."/>
  </car>
</xsl:template>

</xsl:stylesheet>

It uses Muechian grouping, see http://www.jenitennison.com/xslt/grouping/muenchian.xml if you are not familiar with that XSLT 1.0 approach.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!