0

I have some XML that looks like this:

<interp type="flowers color">Here is something concerning flowers and color.</interp>

And I'm trying to transform it into something like this:

<td class="interp">
    <span class="tag">flowers</span>
    <span class="tab">color</span>
    Here is something concerning flowers and color. 
</td>

So this is the XSL I've been trying:

<xsl:template match="interp">
    <td class="interp">
        <xsl:apply-templates select="@type | node()"/>
    </td>
</xsl:template>

<xsl:template match="@type">
    <xsl:for-each select=".">
    <span class="tag">
        <xsl:value-of select="."/>
    </span>
    </xsl:for-each>
</xsl:template> 

But what I get is more like this:

<span class="tag">flowers color</span>
Here is something concerning flowers and color. 

What am I doing wrong, and how can I get these attribute values to separate?

Jonathan
  • 10,571
  • 13
  • 67
  • 103

1 Answers1

0

Using an XSLT 2.0 processor like Saxon 9 you can use <xsl:for-each select="tokenize(., '\s+')">. With XSLT 1.0 check whether your processor supports an extension function or use a template to split or tokenize the attribute value, see http://exslt.org/str/functions/tokenize/index.html.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • I'm just using Firefox, and when I try using the tokenize function, it says "Error during XSLT transformation: An unknown XPath extension function was called." – Jonathan Dec 06 '15 at 22:04
  • Well, I said the `tokenize` approach works with an XSLT 2.0 processor, unfortunately browsers force you to use XSLT 1.0 from 1999. See http://stackoverflow.com/questions/33838519/turn-xml-attribute-with-2-or-more-values-into-svg-x-y-coordinates-using-xsl/33843236#33843236 for an example on how to use a named template to tokenize an attribute value in XSLT 1.0. – Martin Honnen Dec 07 '15 at 09:37