xsl-list
[Top] [All Lists]

Re: [xsl] Selectively convert Attributes to child Elements

2009-05-19 04:51:42
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--