xslt - How to replace commas with spaces in XSL -


i need replace every other comma space in xml output. right now, have latitude , longitude looks this:

-0.52437106918239,0.391509433962264,-0.533805031446541,0.430817610062893,0  -0.547955974842767,0.427672955974843, 

i need coordinates in xml output this:

-0.52437106918239 0.391509433962264, -0.533805031446541 0.430817610062893,0    -0.547955974842767 0.427672955974843 

how can use xslt this? here xsl:

<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"     xmlns:kml="http://www.opengis.net/kml/2.2"> <xsl:output method="text"/>  <xsl:template match="/"> <xsl:apply-templates select="kml:kml/kml:document/kml:placemark/kml:polygon   /kml:outerboundaryis/kml:linearring"/> </xsl:template>    <xsl:template match="kml:linearring"> "polygon((<xsl:value-of select="kml:coordinates"/>))"  </xsl:template> </xsl:stylesheet> 

in xslt 2.0 trivial. use replace().

in xslt 1.0, use template so. call convert-space template on list needs every second comma replaced.

<xsl:template name="convert-space">   <xsl:param name="text"/>   <xsl:choose>     <xsl:when test="contains($text,',')">       <xsl:value-of select="substring-before($text,',')"/>       <xsl:value-of select="' '"/>       <xsl:call-template name="convert-comma">         <xsl:with-param name="text" select="substring-after($text,',')"/>       </xsl:call-template>     </xsl:when>     <xsl:otherwise>       <xsl:value-of select="$text"/>     </xsl:otherwise>   </xsl:choose> </xsl:template>  <xsl:template name="convert-comma">   <xsl:param name="text"/>   <xsl:choose>     <xsl:when test="contains($text,',')">       <xsl:value-of select="substring-before($text,',')"/>       <xsl:value-of select="','"/>       <xsl:call-template name="convert-space">         <xsl:with-param name="text" select="substring-after($text,',')"/>       </xsl:call-template>     </xsl:when>     <xsl:otherwise>       <xsl:value-of select="$text"/>     </xsl:otherwise>   </xsl:choose> </xsl:template> 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -