This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

XML to XML


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>

into:

<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>

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

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
wordID="3">Testing</word>.</line>

Many thanks,
Mick


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]