[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSL2 string result from XSL1 template

Subject: RE: XSL2 string result from XSL1 template
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 14 Apr 2009 13:40:10 +0100
RE:  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:  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) &gt; 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.