Subject: [xsl] XSL2 string result from XSL1 template From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx> Date: Tue, 14 Apr 2009 23:39:35 +1200 |
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 -> |
---|---|---|
Re: [xsl] Which XSLT processor on w, COUTHURES Alain | Thread | RE: [xsl] XSL2 string result from X, Michael Kay |
Re: [xsl] Which XSLT processor on w, himanshu padmanabhi | Date | Re: [xsl] Which XSLT processor on w, Vyacheslav Sedov |
Month |