Subject: Re: [xsl] XSL2 string result from XSL1 template From: Andrew Welch <andrew.j.welch@xxxxxxxxx> Date: Tue, 14 Apr 2009 15:44:22 +0100 |
I'd be tempted to convert the named template into a function, and then the calling code could be: <xsl:variable name="fulltarget" select="f:encode-url(concat($urlprefix,'docs/',$book,'/',$subf,'#',$jid))" as="xs:string"> ...where f:encode-url() returns a single item by wrapping another function which returns the sequence (to avoid the need for string-join). fwiw, you can still use the "as" attribute on named templates: <xsl:template name="whatever" as="xs:string"> which helps narrow down where the problem is (no good here though, because of the way the result is built) 2009/4/14 Trevor Nicholls <trevor@xxxxxxxxxxxxxxxxxx>: > 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 > > -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSL2 string result from X, Trevor Nicholls | Thread | Re: [xsl] XSL2 string result from X, David Carlisle |
RE: [xsl] XSL2 string result from X, Trevor Nicholls | Date | Re: [xsl] XML transformation based , Emiliano Pecis |
Month |