Head-scratching error in an XSLT function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Head-scratching error in an XSLT function

Mark Gibson-8
Hi,
The stylesheet below is causing me a headache, it contains a
function to aide in the transform of an XML Schema.
But all I'm getting from OPS is the following error:

  Failed to compile stylesheet. 1 error detected.

It reports the offending line as the last line of the
xsl:sequence element.

I'm staring at this and double checking the specs and
for the life of me I can not see what is causing the error!

Can anyone help?

BTW, can anyone recommend an XSLT debugger or some way to
get more helpful error messages?

Cheers
- Mark Gibson

<xsl:stylesheet version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsu="http://worksmart.net/ns/xsd-util"
   exclude-result-prefixes="xsu">
       
   <xsl:key name="xsu:types"
     match="/xsd:schema/xsd:complexType|/xsd:schema/xsd:simpleType"
     use="@name"/>

   <xsl:function name="xsu:type-def" as="element()">
     <xsl:param name="elem" as="element()"/>
     <xsl:sequence
       select="if ($elem/complexType)
               then $elem/complexType
               else if ($elem/simpleType)
               then $elem/simpleType
               else if ($elem/@ref)
               then xsu:type-def(/xsd:schema/xsd:element[@name=$elem/@ref])
               else if ($elem/@type and
exists(key('xsu:types',$elem/@type)))
               then key('xsu:types',$elem/@type)
               else key('xsu:types','xsd:anyType')"/>
   </xsl:function>
</xsl:stylesheet>



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Head-scratching error in an XSLT function

Mark Gibson-8
SOLVED.

Mark Gibson wrote:

> Hi,
> The stylesheet below is causing me a headache, it contains a
> function to aide in the transform of an XML Schema.
> But all I'm getting from OPS is the following error:
>
>  Failed to compile stylesheet. 1 error detected.
>
> It reports the offending line as the last line of the
> xsl:sequence element.
>
> I'm staring at this and double checking the specs and
> for the life of me I can not see what is causing the error!
>
> Can anyone help?
>
> BTW, can anyone recommend an XSLT debugger or some way to
> get more helpful error messages?
>
> Cheers
> - Mark Gibson
>
> <xsl:stylesheet version="2.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>   xmlns:xsu="http://worksmart.net/ns/xsd-util"
>   exclude-result-prefixes="xsu">
>    
>   <xsl:key name="xsu:types"
>     match="/xsd:schema/xsd:complexType|/xsd:schema/xsd:simpleType"
>     use="@name"/>
>
>   <xsl:function name="xsu:type-def" as="element()">
>     <xsl:param name="elem" as="element()"/>
>     <xsl:sequence
>       select="if ($elem/complexType)
>               then $elem/complexType
>               else if ($elem/simpleType)
>               then $elem/simpleType
>               else if ($elem/@ref)
>               then xsu:type-def(/xsd:schema/xsd:element[@name=$elem/@ref])
>               else if ($elem/@type and
> exists(key('xsu:types',$elem/@type)))
>               then key('xsu:types',$elem/@type)
>               else key('xsu:types','xsd:anyType')"/>
>   </xsl:function>
> </xsl:stylesheet>
Well, after a long hard talking to the dog, I've solved my own
problem. It seems that there is no context item in functions in XSLT 2.0
(unlike the EXSLT functions extension in 1.0!), and key() requires three
arguments when there is no context item. Thus the XPath statement
should read:

   if ($elem/complexType)
   then $elem/complexType
   else if ($elem/simpleType)
   then $elem/simpleType
   else if ($elem/@ref)
   then xsu:type-def(root($elem)/xsd:schema/xsd:element[@name=$elem/@ref])
   else if ($elem/@type and
exists(key('xsu:types',$elem/@type,root($elem))))
   then key('xsu:types',$elem/@type,root($elem))
   else key('xsu:types','xsd:anyType',root($elem))



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws