[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Typing Variable as AnyURI - Problem

Subject: Re: [xsl] Typing Variable as AnyURI - Problem
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 13 Sep 2012 08:31:48 +0100

Your call to xsl:apply-templates is returning a sequence of text nodes. A sequence of text nodes is not a string (nor is an xs:anyURI), and it cannot be converted to a string by calling the string() or xs:anyURI() functions.

To concatenate a sequence of text nodes into a single text node, which can then be implicitly converted into an untypedAtomic value, and used where an xs:string or xs:anyURI is expected, use xsl:value-of:

<xsl:variable name="VMScall" as="xs:anyURI">
     <xsl:apply-templates select="..."/>

Michael Kay

On 13/09/2012 07:14, Ihe Onwuka wrote:
This stylesheet is supposed to construct an HTTP call.

If I type the variable VMSCall as anyURI I get

net.sf.saxon.trans.XPathException: A sequence of more than one item is
not allowed as the value of variable $VMScall

With the casting in the call to the document function (and an untyped
variable) it works however if the variable is typed (despite casting
to anyURI) it still yields the above error.

If the call to the document function is cast as xs:string I get
net.sf.saxon.trans.XPathException: Exception thrown by URIResolver

My expectation is that if I type the variable as anyURI it should work
without the need to cast the document call. AAMOF I also expected the
call to work without having to type the variable or cast the document
function call.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     <xsl:output indent="yes" omit-xml-declaration="yes"/>
     <xsl:template match="/">
        <xsl:variable name="VMScall" ><xsl:apply-templates/></xsl:variable>
        <xsl:value-of select="document(xs:anyURI($VMScall))"/>
     <xsl:template match="feed">
        <xsl:apply-templates select="product"/>]
     <xsl:template match="product">
        <xsl:apply-templates select="descendant::oc:bundle/externalID"/>
        <xsl:if test="not(position()=last())">,</xsl:if>

Cutdown XML

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:media="http://search.yahoo.com/mrss/"





Current Thread