Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 24th, 2007, 02:40 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default seperate string by ^

<xsl:variable name="HISTORY" select="./@history" />

The result is a String like

abc^defg^ttt^bbb^ggg

I am tring to get like

abc
defg
ttt
bbb
ggg

-------------------------------------------------------------------------------------


<xsl:variable name="HISTORY_BEFORE" select="substring-before($HISTORY,'^')" />
<xsl:variable name="HISTORY_AFTER" select="substring-after($HISTORY,'^')" />
<xsl:choose>
    <xsl:when test="string-length($HISTORY_BEFORE) > 0" >
        <xsl:value-of select="substring-before($HISTORY,'^')" />
        <br />
        <xsl:if test="string-length($HISTORY_AFTER) > 0">
            <xsl:value-of select="substring-before($HISTORY_AFTER,'^')" /><br />
            <xsl:value-of select="substring-after($HISTORY_AFTER,'^')" />
        </xsl:if>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="./@history" />
    </xsl:otherwise>
</xsl:choose>
Reply With Quote
  #2 (permalink)  
Old July 24th, 2007, 04:32 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi,

Please post some of the XML and someone can help.

Bones


Reply With Quote
  #3 (permalink)  
Old July 24th, 2007, 05:55 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I suspect an error in the code you haven't shown us - for example, the context might be wrong. Please show a complete (but small) XML source document and stylesheet, this is much easier to debug than a fragment.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old July 24th, 2007, 08:29 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<test>
<testdata history="aaa^bbb^ccc^ddd"></testdata>
</test>

-----------------------------------
 <xsl:variable name="HISTORY" select="../test/testdata/@history" />

<xsl:variable name="HISTORY_BEFORE" select="substring-before($HISTORY,'^')" />
<xsl:variable name="HISTORY_AFTER" select="substring-after($HISTORY,'^')" />
<xsl:choose>
    <xsl:when test="string-length($HISTORY_BEFORE) > 0" >
        <xsl:value-of select="substring-before($HISTORY,'^')" />
        <br />
        <xsl:if test="string-length($HISTORY_AFTER) > 0">
            <xsl:value-of select="substring-before($HISTORY_AFTER,'^')" /><br />
            <xsl:value-of select="substring-after($HISTORY_AFTER,'^')" />
        </xsl:if>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="./@history" />
    </xsl:otherwise>
</xsl:choose>
Reply With Quote
  #5 (permalink)  
Old July 24th, 2007, 08:35 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<document>
    <testxml>
        <test1>
        <test1a>
                          <test>
                                 <testdata history="aaa^bbb^ccc^ddd"></testdata>
                          </test>
                         </test1a>
                </test1>
            </testxml>
</document>
Reply With Quote
  #6 (permalink)  
Old July 24th, 2007, 08:51 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi, You should use the tokenize function

tokenize(string,pattern)

something like

for $w in tokenize($History,'^') return $w


Reply With Quote
  #7 (permalink)  
Old July 24th, 2007, 10:08 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using version 1.0

is it working with that version?
Reply With Quote
  #8 (permalink)  
Old July 25th, 2007, 02:00 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As I said, the problem could well be that the context isn't set up correctly for your code to run. The fact that you haven't demonstrated the context suggests that you haven't understood its importance.

I'm also confused as to why you have shown two different versions of your source document, without any explanation.

As I said before, please provide a complete runnable example that demonstrates the problem, so we can tell you where you went wrong.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreatBackup:=True but in seperate folder mona_upm84 Excel VBA 0 July 18th, 2008 12:07 AM
Call to subroutine from seperate workbook Coby Excel VBA 2 February 1st, 2008 10:15 PM
Why not seperate OBJ layer susahin80 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 January 19th, 2007 03:51 PM
1 form, contains two seperate controls EricJ General .NET 2 August 10th, 2005 04:48 AM
Seperate Code JsonTerre1 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 7th, 2004 04:38 PM



All times are GMT -4. The time now is 05:00 AM.


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