xsl-list
[Top] [All Lists]

Re: [xsl] Constructing complex xs:string in variable

2019-10-09 09:43:35
And to explain why David's version works: value-of and xsl:text both result in 
text nodes, not strings. So a sequence of xsl:value-of and xsl:text 
instructions will result in a sequence of text nodes when are then converted to 
strings resulting in a sequence of strings.

Wrapping everything in a single xsl:value-of results in a single text node and 
thus a single string.

Looking at this now I realize it never occurred to me that xsl:value-of can 
have content and not just a @select attribute. Learn something new every day.

Cheers,

E.

--
Eliot Kimber
http://contrext.com
 

On 10/9/19, 8:30 AM, "David Carlisle 
d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

    On Wed, 9 Oct 2019 at 14:27, Christian Roth
    mulberrytech-lists(_at_)kriro(_dot_)de 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
    wrote:
    >
    > [re-sending - initial one didn't make it to the list…?]
    >
    > Hello,
    >
    > I'm using XSLT2.
    >
    > I need to construct a complex string in a variable. I wanted to use XSLT 
instructions for this, not pure XPath. I'm struggling with coercing the result 
of the <xsl:variable> body to a single xs:string, not a sequence of xs:string:
    >
    >
    > <xsl:variable name="var" as="xs:string">
    >   <xsl:text>prefix</xsl:text>
    >   <xsl:value-of select="'part1'"/>
    >   <!-- follows more complex code producing further fragments of desired 
result string -->
    > </xsl:variable>
    >
    >
    > This gives me the error message (Saxon HE 9): "A sequence of more than 
one item is not allowed as the value of variable $var ("prefix", "part1")"
    >
    > Of course, I could declare the variable as xs:string+ and then use 
string-join( $var, '' ) on every use of $var, or create another variable that 
holds the concatenated result of $var.
    >
    
    <xsl:variable name="var" as="xs:string">
    <xsl:value-of>
      <xsl:text>prefix</xsl:text>
      <xsl:value-of select="'part1'"/>
      <!-- follows more complex code producing further fragments of
    desired result string -->
    </xsl:value-of>
    </xsl:variable>
    
    David
    
    
    
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>