aspose file tools*
The moose likes XML and Related Technologies and the fly likes XSLT How can i divide a value in 2 ? IndexOf/substring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT How can i divide a value in 2 ? IndexOf/substring" Watch "XSLT How can i divide a value in 2 ? IndexOf/substring" New topic
Author

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

Michel Nadeau
Greenhorn

Joined: Jul 14, 2004
Posts: 2
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

Joined: Jul 14, 2004
Posts: 2
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSLT How can i divide a value in 2 ? IndexOf/substring
 
Similar Threads
Input from keyboard
Java Web Services 2
two radix solution to convert Roman numerals
Help with JSON
Variables in Java