Click to See Complete Forum and Search --> : XSLT - Add comma


sunsilk10
November 10th, 2008, 06:23 AM
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

Alain COUTHURES
November 10th, 2008, 07:13 AM
Only a recursive named template can do that : you have to retrieve the first x,y coordinates then call the template again...

sunsilk10
November 10th, 2008, 08:29 AM
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>

Alain COUTHURES
November 10th, 2008, 10:45 AM
<coordinates><xsl:call-template name="coord"><xsl:with-param name="list" select="gml:posList" /></xsl:call-template></coordinates>


<xsl:template name="coord">
<xsl:param 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:otherwise>
<xsl:value-of select="$afterx"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

(not tested...)

sunsilk10
November 11th, 2008, 07:16 AM
Perfect!

Thank you