|
-
November 10th, 2008, 07:23 AM
#1
XSLT - Add comma
Hi I have an element
<PostList>450 400 600 700 900 299</PosList>
I want to transform it to
<Coord>450,400 600,700 900,299</Coord> i.e. add comma between the x,y coordinates
Any suggestions?
Many Thanks
-
November 10th, 2008, 08:13 AM
#2
Re: XSLT - Add comma
Only a recursive named template can do that : you have to retrieve the first x,y coordinates then call the template again...
Last edited by Alain COUTHURES; November 10th, 2008 at 08:16 AM.
-
November 10th, 2008, 09:29 AM
#3
Re: XSLT - Add comma
Thanks for the reply. Any idea how the recursive function could be implemented in my example below?
<xsl:template match="gml:LineString">
<MultiLineString>
<LineStringMember>
<LineString>
<coordinates><xsl:value-of select="gml: posList" /></coordinates>
</LineString>
</LineStringMember>
</MultiLineString>
</xsl:template>
<gml:LineString>
<gml: posList>
45.256 -110.45 46.46 -109.48 43.84 -109.86
</gml: posList>
</gml:LineString>
-
November 10th, 2008, 11:45 AM
#4
Re: XSLT - Add comma
<coordinates><xsl:call-template name="coord"><xsl:with-param name="list" select="gml osList" /></xsl:call-template></coordinates>
<xsl:template name="coord">
<xsl aram name="list"/>
<xsl:value-of select="substring-before($list,' ')"/>
<xsl:text>,</xsl:text>
<xsl:variable name="afterx" select="substring-after($list,' ')"/>
<xsl:choose>
<xsl:when test="contains($afterx,' ')">
<xsl:value-of select="substring-before($afterx,' ')"/>
<xsl:text> </xsl:text>
<xsl:call-template name="coord">
<xsl:with-param name="list" select="substring-after($afterx,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl therwise>
<xsl:value-of select="$afterx"/>
</xsl therwise>
</xsl:choose>
</xsl:template>
(not tested...)
-
November 11th, 2008, 08:16 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|