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> 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, ' ')"> <word><xsl:value-of select="substring-before($text, ' ')"/></word> <xsl:call-template name="test"> <xsl:with-param name="text" select="substring-after($text, ' ')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <word><xsl:value-of select="$text"/></word> </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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] RE: Help...urgent!!!, Michael Kay | Thread | Re: [xsl] XML to XML, Rob Lugt |
RE: [xsl] Difference between "/" an, Rene de Vries | Date | [xsl] creating mutiple columns, Michael Zehrer |
Month |