|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 24th, 2007, 03:40 PM
|
|
Registered User
|
|
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|

July 24th, 2007, 05:32 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Hi,
Please post some of the XML and someone can help.
Bones
|

July 24th, 2007, 06:55 PM
|
 |
Wrox Author
Points: 12,735, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

July 24th, 2007, 09:29 PM
|
|
Registered User
|
|
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<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>
|

July 24th, 2007, 09:35 PM
|
|
Registered User
|
|
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<document>
<testxml>
<test1>
<test1a>
<test>
<testdata history="aaa^bbb^ccc^ddd"></testdata>
</test>
</test1a>
</test1>
</testxml>
</document>
|

July 24th, 2007, 09:51 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Hi, You should use the tokenize function
tokenize(string,pattern)
something like
for $w in tokenize($History,'^') return $w
|

July 24th, 2007, 11:08 PM
|
|
Registered User
|
|
Join Date: Jul 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using version 1.0
is it working with that version?
|

July 25th, 2007, 03:00 AM
|
 |
Wrox Author
Points: 12,735, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |