Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old September 3rd, 2010, 09:57 AM
Authorized User
 
Join Date: Mar 2010
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Default 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
 
Old September 3rd, 2010, 10:04 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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
 
Old September 3rd, 2010, 10:06 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 3rd, 2010, 10:17 AM
Authorized User
 
Join Date: Mar 2010
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Default

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
 
Old September 3rd, 2010, 10:20 AM
Authorized User
 
Join Date: Mar 2010
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:function pass param to attribute of xsl:instruction bonekrusher XSLT 4 March 31st, 2009 09:06 AM
Javascript Function return save in XSL Variable Vrokad XSLT 2 June 2nd, 2007 02:54 AM
Java to XSL // Return Array go4java XSLT 3 June 29th, 2006 06:05 PM
how to return nodeset in template in xsl:variable alexshiell XSLT 3 March 18th, 2005 01:36 PM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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