[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XML to XML

Subject: XML to XML
From: m.vanrootseler@xxxxxxxxx
Date: Fri, 22 Jun 2001 11:07:46 +0200
 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


Current Thread
  • XML to XML
    • m . vanrootseler - Fri, 22 Jun 2001 05:13:08 -0400 (EDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.