|
Subject: RE: [xsl] XSL2 string result from XSL1 template From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 14 Apr 2009 13:40:10 +0100 |
Your template is returning a sequence of text nodes. The simplest way to
convert this to a single string is:
<xsl:variable name="fulltarget" as="xs:string">
<xsl:value-of>
<xsl:call-template name="encode-url">
<xsl:with-param name="str"
select="concat($urlprefix,'docs/',$book,'/',$subf,'#',$jid)" />
</xsl:call-template>
</xsl:value-of>
</xsl:variable>
the effect of the xsl:value-of instruction is to convert the sequence of
text nodes into a single text node.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Trevor Nicholls [mailto:trevor@xxxxxxxxxxxxxxxxxx]
> Sent: 14 April 2009 12:40
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] XSL2 string result from XSL1 template
>
> I am running an XSL 2.0 stylesheet which includes some
> ubiquitous XSL 1.0 stylesheets which provide some standard features.
>
> The variable definition here gives an error at runtime:
>
> <xsl:variable name="fulltarget" as="xs:string">
> <xsl:call-template name="encode-url">
> <xsl:with-param name="str"
> select="concat($urlprefix,'docs/',$book,'/',$subf,'#',$jid)" />
> </xsl:call-template>
> </xsl:variable>
>
> The error is XTTE0570: A sequence of more than one item is
> not allowed as the value of variable $fulltarget
>
>
> OK, I understand the error, and I could write an XSL 2
> version of the encode-url template that would return a single
> string, but how would I modify the CALLING stylesheet to work
> with what I already have?
>
> The called template looks like this ($safe, $ascii, $latin1
> and $hex are what you would expect):
>
> <xsl:template name="encode-url">
> <xsl:param name="str"/>
> <xsl:if test="$str">
> <xsl:variable name="first-char" select="substring($str,1,1)"/>
> <xsl:choose>
> <xsl:when test="contains($safe,$first-char)">
> <xsl:value-of select="$first-char"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:variable name="charval">
> <xsl:choose>
> <xsl:when test="contains($ascii,$first-char)">
> <xsl:value-of
> select="string-length(substring-before($ascii,$first-char)) + 32"/>
> </xsl:when>
> <xsl:when test="contains($latin1,$first-char)">
> <xsl:value-of
> select="string-length(substring-before($latin1,$first-char)) + 160"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:message terminate="no">Warning: string
> contains an out of range character.</xsl:message>
> <xsl:text>63</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:variable name="hex-digit1"
> select="substring($hex,floor($charval div 16) + 1,1)"/>
> <xsl:variable name="hex-digit2"
> select="substring($hex,$charval mod
> 16 + 1,1)"/>
> <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:if test="string-length($str) > 1">
> <xsl:call-template name="encode-url">
> <xsl:with-param name="str" select="substring($str,2)"/>
> </xsl:call-template>
> </xsl:if>
> </xsl:if>
> </xsl:template>
>
>
> Thanks in advance
>
> Cheers
> Trevor
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] XSL2 string result from XSL1 , Trevor Nicholls | Thread | RE: [xsl] XSL2 string result from X, Trevor Nicholls |
| Re: [xsl] Which XSLT processor on w, Vyacheslav Sedov | Date | Re: [xsl] XSL2 string result from X, David Carlisle |
| Month |