RE: [xsl] Type error with variable as=xs:string using xsl:choose

Subject: RE: [xsl] Type error with variable as=xs:string using xsl:choose
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 7 Sep 2006 11:09:28 +0100
I think Joe got it wrong. It's not the otherwise branch that's the problem,
it's the when:

<xsl:when 
>test="contains($xsrc,'/images/images/')">
><xsl:text>images/</xsl:text>
><xsl:value-of select="substring-after($xsrc,'/images/images/')" /> 
></xsl:when> 

xsl:text creates a text node, xsl:value-of creates a second text node, and
you can't convert a sequence of two text nodes to a single string.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Trevor Nicholls [mailto:trevor@xxxxxxxxxxxxxxxxxx] 
> Sent: 07 September 2006 11:01
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Type error with variable as=xs:string 
> using xsl:choose
> 
> I can't see how $xsrc can have more than one node:
> 
> <xsl:variable name="xsrc" as="xs:string"> <xsl:value-of 
> select="@src" /> </xsl:variable>
> 
> Then follows the variable declaration in my original email, below.
> 
> The actual XML element on which the template is choking is this one:
> 
> <icon src="../../abc/images/def/icon_arrow.gif" dpi="96"/>
> 
> Checking my logs, I have found that the error only occurs for 
> a few instances of <icon>; most are converted without problems, e.g.
> 
> <icon src="images/edf/features/pivot.gif" dpi="96"/>
> 
> In fact, it looks like it is the "../../" prefix which may be 
> the problem - but the src values which include this are valid 
> and correct.
> 
> Does this extra information change the advice at all?
> 
> Cheers
> Trevor
>  
> -----Original Message-----
> From: Joe Fawcett [mailto:joefawcett@xxxxxxxxxxx]
> Sent: Thursday, 7 September 2006 9:41 p.m.
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Type error with variable as=xs:string 
> using xsl:choose
> 
> You defined the variable as a single string instance.
> If $xsrc has more than one node and the xsl:otherwise 
> instruction kicks in then this is an error.
> 
> Perhaps change to:
> 
> <xsl:otherwise>
> <xsl:value-of select="$xsrc[1]" />
> </xsl:otherwise>
> 
> Joe
> 
> 
> 
> >From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >Subject: [xsl]  Type error with variable as=xs:string using 
> xsl:choose
> >Date: Thu, 7 Sep 2006 21:29:25 +1200
> >
> >The following variable definition is giving me the error
> >"XTTE0570: A sequence of more than one item is not allowed 
> as the value 
> >of variable normsrc"
> >
> >I'm using Saxon 8.6.1 on Windows XP.
> >
> >====
> ><xsl:variable name="normsrc" as="xs:string"> <xsl:choose> <xsl:when 
> >test="contains($xsrc,'/images/images/')">
> ><xsl:text>images/</xsl:text>
> ><xsl:value-of select="substring-after($xsrc,'/images/images/')" /> 
> ></xsl:when> <xsl:when test="contains($xsrc,'/images/')">
> ><xsl:text>images/</xsl:text>
> ><xsl:value-of select="substring-after($xsrc,'/images/')" /> 
> </xsl:when> 
> ><xsl:otherwise> <xsl:value-of select="$xsrc" /> </xsl:otherwise> 
> ></xsl:choose> </xsl:variable> ====
> >
> >If I drop the as="xs:string" attribute it works perfectly, 
> but I'm sure 
> >I've got exactly this construction elsewhere without complaint. One 
> >difference with this logic is that the 'when' tests overlap: 
> any $xsrc 
> >that matches the first 'when' will also match the second, but I 
> >understood that 'choose'
> >will
> >only make one choice. Am I confused?
> >
> >Cheers
> >Trevor

Current Thread