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:value-of>
     <xsl:apply-templates select="..."/>
  </xsl:value-of>
</xsl:variable>

Michael Kay
Saxonica


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.



Stylesheet

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xmlns:xs="http://www.w3.org/2001/XMLSchema";
     xmlns:oc="http://extend.com/opencase/2.0";
         version="2.0">
     <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>
     <xsl:template match="feed">
        <xsl:text>http://blah?entityType=VOD&amp;filters=beid:equals:[</xsl:text>
        <xsl:apply-templates select="product"/>]
     </xsl:template>
     <xsl:template match="product">
        <xsl:apply-templates select="descendant::oc:bundle/externalID"/>
        <xsl:if test="not(position()=last())">,</xsl:if>
     </xsl:template>
</xsl:stylesheet>


Cutdown XML


<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:media="http://search.yahoo.com/mrss/";
       xmlns:oc="http://extend.com/opencase/2.0";
       xmlns:ocmedia="http://extend.com/opencase/2.0/ocmedia";>

<product>

             <oc:bundle>
                <name>VoD_70</name>
                <altCode/>
                <uuid>4c219204-4bd9-42d9-8b39-9bd7f2b43a93</uuid>
                <externalID>Asset_0097_VoD_70</externalID>

                <createDate>2012-08-17T14:48:47.863Z</createDate>
                <lastModified>2012-08-17T14:51:16.237Z</lastModified>
                <isActive>true</isActive>
             </oc:bundle>
</product>
<product>
             <oc:bundle>
                <name>VoD_150</name>
                <altCode/>
                <uuid>7a93f556-cf0c-4761-8642-f5013b83b03f</uuid>
                <externalID>Asset_0177_VoD_150</externalID>

                <createDate>2012-08-17T14:48:59.820Z</createDate>
                <lastModified>2012-08-17T14:51:17.127Z</lastModified>
                <isActive>true</isActive>
             </oc:bundle>
</product>
</feed>

Current Thread