Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT How can i divide a value in 2 ? IndexOf/substring

 
Michel Nadeau
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i want to split a value (Always delimited by a space ' ') in two.
Considering theres no indexOf what can i do ? x()

Here is a part of the XML :
<Point>
<pos>-79.377775 43.649249999999995<pos>
</Point>

And i want to translate that into this :
<Point>
<coord>
<X>-79.377775</X>
<Y>43.649249999999995</Y>
</coord>
</Point>

Thanks for the help!
 
Michel Nadeau
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok finally found how to make this work.
Used example from :
Jeni Tennison

My working XSL :

<xsl:template match="Point">
<Point>
<coord>
<X>
<xsl:call-template name="firstIndexOf">
<xsl:with-param name="string" select="pos" />
<xsl:with-param name="char" select="' '" />
</xsl:call-template>
</X>
<Y>
<xsl:call-template name="lastIndexOf">
<xsl:with-param name="string" select="pos" />
<xsl:with-param name="char" select="' '" />
</xsl:call-template>
</Y>
</coord>
</Point>
</xsl:template>

<xsl:template name="lastIndexOf">
<xsl aram name="string" />
<xsl aram name="char" />
<xsl:choose>
<xsl:when test="contains($string, $char)">
<xsl:call-template name="lastIndexOf">
<xsl:with-param name="string"
select="substring-after($string, $char)" />
<xsl:with-param name="char" select="$char" />
</xsl:call-template>
</xsl:when>
<xsl therwise><xsl:value-of select="$string" /></xsl therwise>
</xsl:choose>
</xsl:template>

<xsl:template name="firstIndexOf">
<xsl aram name="string" />
<xsl aram name="char" />
<xsl:choose>
<xsl:when test="contains($string, $char)">
<xsl:call-template name="lastIndexOf">
<xsl:with-param name="string"
select="substring-before($string, $char)" />
<xsl:with-param name="char" select="$char" />
</xsl:call-template>
</xsl:when>
<xsl therwise><xsl:value-of select="$string" /></xsl therwise>
</xsl:choose>
</xsl:template>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic