CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    43

    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

  2. #2
    Join Date
    Apr 2008
    Posts
    12

    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.

  3. #3
    Join Date
    Apr 2005
    Posts
    43

    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>

  4. #4
    Join Date
    Apr 2008
    Posts
    12

    Re: XSLT - Add comma

    <coordinates><xsl:call-template name="coord"><xsl:with-param name="list" select="gmlosList" /></xsl:call-template></coordinates>


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

    (not tested...)

  5. #5
    Join Date
    Apr 2005
    Posts
    43

    Re: XSLT - Add comma

    Perfect!

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured