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

September 3rd, 2010, 09:57 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
how to force the return value of xsl:function to be a string
Hi,
I am trying to use <xsl:value-of select="my_func()"/>, but I get spaces in the output. This happens cause the return value is a sequence (I guess); how can I force it to be a string?
I am currently using a wrapper function, which does string-join, like this: http://paste.pocoo.org/show/258039/ I guess there is an easier way, but I don't know of one.
Thx,
apollo13
|
|

September 3rd, 2010, 10:04 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Well you can fix the xsl:value-of
Code:
<xsl:value-of select="my_func()" separator=""/>
or you can fix the function e.g.
Code:
<xsl:function name="bap:to_csv_internal" as="xs:string">
<xsl:param name="data" as="xs:string+"/>
<xsl:sequence select="string-join((bap:quote_for_csv($data[1]), $data[position() gt 1]), '')"/>
</xsl:function>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

September 3rd, 2010, 10:06 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Converting a sequence to a string will by default add spaces between the sequence items.
If you use <xsl:value-of select="sequence" separator =""/> then the separator will be empty string.
However, you don't show us your function, so it might be that the conversion from sequence to string might already have happened in the function, so changing the value on this <xsl:value-of> instruction might make no difference.
|
|

September 3rd, 2010, 10:17 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
right, stupid me, I am using:
Code:
<xsl:function name="bap:to_csv" as="xs:string">
<xsl:param name="data" as="xs:string+"/>
<xsl:value-of select="string-join((for $i in $data return bap:quote_for_csv($i)), $csv_delimiter)"/>
</xsl:function>
now.
thx for the quick reply,
Florian
|
|

September 3rd, 2010, 10:20 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by samjudson
However, you don't show us your function, so it might be that the conversion from sequence to string might already have happened in the function, so changing the value on this <xsl:value-of> instruction might make no difference.
|
The function in question is in the linked paste (bap:to_csv), but thx, I already solved it.
|
|
 |