Re: [xsl] Selectively convert Attributes to child Elements

Subject: Re: [xsl] Selectively convert Attributes to child Elements
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Tue, 19 May 2009 10:51:07 +0200
The Web Maestro schrieb:
Thank you! That was very helpful! One final addition: how do I get
this new element:

<tags>news,breaking news</tags>

Converted to:

  <tags>
    <tag>news</tag>
    <tag>breaking news</tag>
  </tags>

Ciao Maestro,


in 1.0, use str:split(), allegro ma non troppo:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:str="http://exslt.org/strings";
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="tags">
    <!-- To see how it works, uncomment the following line:
    <xsl:copy-of select="str:split( . , ',')"/> -->
    <xsl:copy>
      <xsl:for-each select="str:split( . , ',')">
        <tag><xsl:value-of select="."/></tag>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

In 2.0, use tokenize() instead.

Michael Ludwig

Current Thread