Bug in XPath expression

Thursday, 30 August 2012 · 3 messages · last reply 31 Aug 2012
HR
Hans-Juergen Rennau30 Aug 2012 14:46 #
Hello, if I am not mistaken, the following code demonstrates a bug. The code extracts from a schema a type definition, referenced by an element declaration. The second line determines the element whose type definition is sought. In mode 1, the type definition is not found, in mode 2 it is found. With Saxon, modes 1 and 2 are successful. Strangely, at least with my XSD the error occurs only if the type to be found is xs:simpleType - it does not occur if it is xs:complexType. Kind regards, Hans-Juergen ===================================
declare variable $schemas := /*;
declare variable $elem := ($schemas//xs:element[@type eq 't:Room'])[1];
declare variable $mode := 1;

declare function local:getTypeDef($elem as element(xs:element)) as element()? {
   let $type := $elem/@type
   return
if (empty($type)) then $elem/(xs:simpleType, xs:complexType) else
   let $qname := resolve-QName($type, $elem)
   let $lname := local-name-from-QName($qname)
   let $uri := namespace-uri-from-QName($qname)
   return
      if (empty($uri)) then
         let $actSchemas := $schemas[not(@targetNamespace)]
         return $actSchemas/(xs:complexType, xs:simpleType)[@name eq $lname]
      else
         if ($mode eq 1) then
            $schemas[@targetNamespace eq $uri]/(xs:complexType, xs:simpleType)[@name eq $lname]
         else
            let $actSchemas := $schemas[@targetNamespace eq $uri]
            let $types := $actSchemas/(xs:complexType, xs:simpleType)
            return $types[@name eq $lname]
};

<typeDef>{
   local:getTypeDef($elem)
}</typeDef>
==============================================
CG
Christian Grün30 Aug 2012 18:39 #
Hi Hans-Jürgen, do you have an example document to get the query running? Thanks in advance, Christian
Quoted text · Hans-Juergen Rennau · 55 lines
> if I am not mistaken, the following code demonstrates a bug. The code > extracts from a schema a type definition, referenced by an element > declaration. The second line determines the element whose type definition is > sought. > > In mode 1, the type definition is not found, in mode 2 it is found. With > Saxon, modes 1 and 2 are successful. > > Strangely, at least with my XSD the error occurs only if the type to be > found is xs:simpleType - it does not occur if it is xs:complexType. > > Kind regards, > Hans-Juergen > > =================================== > > declare variable $schemas := /*; > declare variable $elem := ($schemas//xs:element[@type eq 't:Room'])[1]; > declare variable $mode := 1; > > declare function local:getTypeDef($elem as element(xs:element)) as > element()? { > let $type := $elem/@type > return > > if (empty($type)) then $elem/(xs:simpleType, xs:complexType) else > > let $qname := resolve-QName($type, $elem) > let $lname := local-name-from-QName($qname) > let $uri := namespace-uri-from-QName($qname) > return > if (empty($uri)) then > let $actSchemas := $schemas[not(@targetNamespace)] > return $actSchemas/(xs:complexType, xs:simpleType)[@name eq $lname] > else > if ($mode eq 1) then > $schemas[@targetNamespace eq $uri]/(xs:complexType, > xs:simpleType)[@name eq $lname] > else > let $actSchemas := $schemas[@targetNamespace eq $uri] > let $types := $actSchemas/(xs:complexType, xs:simpleType) > return $types[@name eq $lname] > }; > > <typeDef>{ > local:getTypeDef($elem) > }</typeDef> > > ============================================== > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
CG
Christian Grünin reply to Hans-Juergen Rennau, 30 Aug 2012, 14:4631 Aug 2012 14:23 #
..fixed [1]! As usual, new snapshots are available [2]. Christian [1] https://github.com/BaseXdb/basex/issues/567 [2] http://files.basex.org/releases/latest/
Quoted text · Hans-Juergen Rennau · 58 lines
On Thu, Aug 30, 2012 at 2:46 PM, Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Hello, > > if I am not mistaken, the following code demonstrates a bug. The code > extracts from a schema a type definition, referenced by an element > declaration. The second line determines the element whose type definition is > sought. > > In mode 1, the type definition is not found, in mode 2 it is found. With > Saxon, modes 1 and 2 are successful. > > Strangely, at least with my XSD the error occurs only if the type to be > found is xs:simpleType - it does not occur if it is xs:complexType. > > Kind regards, > Hans-Juergen > > =================================== > > declare variable $schemas := /*; > declare variable $elem := ($schemas//xs:element[@type eq 't:Room'])[1]; > declare variable $mode := 1; > > declare function local:getTypeDef($elem as element(xs:element)) as > element()? { > let $type := $elem/@type > return > > if (empty($type)) then $elem/(xs:simpleType, xs:complexType) else > > let $qname := resolve-QName($type, $elem) > let $lname := local-name-from-QName($qname) > let $uri := namespace-uri-from-QName($qname) > return > if (empty($uri)) then > let $actSchemas := $schemas[not(@targetNamespace)] > return $actSchemas/(xs:complexType, xs:simpleType)[@name eq $lname] > else > if ($mode eq 1) then > $schemas[@targetNamespace eq $uri]/(xs:complexType, > xs:simpleType)[@name eq $lname] > else > let $actSchemas := $schemas[@targetNamespace eq $uri] > let $types := $actSchemas/(xs:complexType, xs:simpleType) > return $types[@name eq $lname] > }; > > <typeDef>{ > local:getTypeDef($elem) > }</typeDef> > > ============================================== > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >

⚡Generated with XQuery