Subject: RE: [xsl] XSL2 string result from XSL1 template From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx> Date: Wed, 15 Apr 2009 01:45:26 +1200 |
Oh cool. I had forgotten that value-of could be used like that, but now you show it, it's obvious. Thank you T -----Original Message----- From: Michael Kay [mailto:mike@xxxxxxxxxxxx] Sent: Wednesday, 15 April 2009 12:40 a.m. To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] XSL2 string result from XSL1 template 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 -> |
---|---|---|
RE: [xsl] XSL2 string result from X, Michael Kay | Thread | Re: [xsl] XSL2 string result from X, Andrew Welch |
Re: [xsl] XML transformation based , Vasu Chakkera | Date | Re: [xsl] XSL2 string result from X, Andrew Welch |
Month |