 |
| 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
|
|
|
|

July 24th, 2007, 02:40 PM
|
|
Registered User
|
|
Join Date: Jul 2007
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, 04:32 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Hi,
Please post some of the XML and someone can help.
Bones
|
|

July 24th, 2007, 05:55 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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, 08:29 PM
|
|
Registered User
|
|
Join Date: Jul 2007
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, 08:35 PM
|
|
Registered User
|
|
Join Date: Jul 2007
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, 08:51 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Hi, You should use the tokenize function
tokenize(string,pattern)
something like
for $w in tokenize($History,'^') return $w
|
|

July 24th, 2007, 10:08 PM
|
|
Registered User
|
|
Join Date: Jul 2007
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, 02:00 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
|
|
 |