Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 9th, 2005, 03:39 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default string split

I have a xml that has values

<values>
  1 172.25600000 0.06176690
  2 25.91090000 0.35879400
  3 5.53335000 0.70071300
</values>

I need to create an xsl that looks like

172.25600000 1 0.06176690
25.91090000 2 0.35879400
5.53335000 3 0.70071300

and

1 2 3
172.25600000 25.91090000 5.53335000
0.06176690 0.35879400 0.70071300

can someone help me out
thanks


  #2 (permalink)  
Old August 10th, 2005, 04:53 AM
Authorized User
 
Join Date: Jul 2004
Location: Oxford, , United Kingdom.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would probably parse the text first to create xml nodes:

Something like this:

<xsl:stylesheet version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
        <xsl:variable name="xml">
            <xsl:call-template name="toXml"><xsl:with-param name="values" select="values" /></xsl:call-template>
        </xsl:variable>

        <p>
            <xsl:for-each select="msxsl:node-set($xml)/value">
                <xsl:value-of select="concat(y, '#xa0;#xa0;', x, '#xa0;#xa0;', z)" /> <br />
            </xsl:for-each>
        </p>
        <p>
            <xsl:for-each select="msxsl:node-set($xml)/value/x">
                <xsl:value-of select="concat(., '#xa0;#xa0;')" />
            </xsl:for-each>
            <br />
            <xsl:for-each select="msxsl:node-set($xml)/value/y">
                <xsl:value-of select="concat(., '#xa0;#xa0;')" />
            </xsl:for-each>
            <br />
            <xsl:for-each select="msxsl:node-set($xml)/value/z">
                <xsl:value-of select="concat(., '#xa0;#xa0;')" />
            </xsl:for-each>

        </p>



    </xsl:template>


    <xsl:template name="toXml">
        <xsl:param name="values" />

        <xsl:variable name="val1" select="substring-before(substring-after($values, ' '), ' ')" />
        <xsl:variable name="next1" select="substring-after($values, $val1)" />

        <xsl:variable name="val2" select="substring-before(substring-after($next1, ' '), ' ')" />
        <xsl:variable name="next2" select="substring-after($next1, $val2)" />

        <xsl:variable name="valtemp" select="substring-before(substring-after($next2, ' '), ' ')" />

        <xsl:variable name="val3">
            <xsl:choose>
                <xsl:when test="string-length($valtemp) > 0">
                    <xsl:value-of select="$valtemp" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="substring-after($next2, ' ')" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <value>
            <x><xsl:value-of select="$val1" /></x>
            <y><xsl:value-of select="$val2" /></y>
            <z><xsl:value-of select="$val3" /></z>
        </value>

        <xsl:variable name="next3" select="substring-after($next2, $val3)" />

        <xsl:if test="string-length($next3) > 0">
            <xsl:call-template name="toXml"><xsl:with-param name="values" select="$next3" /></xsl:call-template>
        </xsl:if>

    </xsl:template>


</xsl:stylesheet>

Cheers

Bryan



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to split string krevathi1912 Access VBA 10 September 6th, 2007 02:21 AM
How to split a string lily611 General .NET 5 March 18th, 2005 01:16 PM
string split by : crmpicco Classic ASP Basics 3 February 10th, 2005 07:49 AM
String.Split bbhill General .NET 2 April 10th, 2004 05:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.