[xsl] XML to XML

Subject: [xsl] XML to XML
From: m.vanrootseler@xxxxxxxxx
Date: Fri, 22 Jun 2001 11:07:46 +0200
Hi all,

I found a solution for the problem I was battling with last week in Dave's
FAQ. The XSL I found only solves part of my problem though. I want to
convert the following XML:

<line>One two. Testing.</line>


<line><word>One</word> <word>two</word>. <word>Testing</word>.</line>

With the XSL below I can 'wrap' the <word> tag around words but the problem
is that any punctuation is included inside the tag as well. What I get is:

<line><word>One</word> <word>two.</word> <word>Testing.</word></line>

Has anyone any ideas how I can copy any full stops and commas but prevent
them from getting insde the <word> tags?

<xsl:template match="text()">
   <xsl:call-template name="test"/><br/>

<xsl:template name="test">
   <xsl:param name="text" select="."/>
         <xsl:when test="contains($text, ' ')">
            &lt;word&gt;<xsl:value-of select="substring-before($text, '
            <xsl:call-template name="test">
               <xsl:with-param name="text" select="substring-after($text, '
            &lt;word&gt;<xsl:value-of select="$text"/>&lt;/word&gt;

Problem number two. I want to add an atribute to the <word> tag which gives
the position of the word in the line: <word wordID=" ">. I've tried
<xsl:value-of select="position()"/> but this, of course, always returns '1'
due to, I guess, the recursion. Has anyone got any ideas how to get the
actual position of the word, so I get:

<line><word wordID="1">One</word> <word wordID="2">two</word>. <word

Many thanks,

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread