xsl-list
[Top] [All Lists]

Re: [xsl] How to compare two QName values in an XML Schema?

2011-04-08 11:41:16


<xsl:variable name="base-type-qname" 
select="resolve-QName(xs:schema/xs:simpleType[2]/xs:restriction/@base, 
xs:schema/xs:simpleType[2]/xs:restriction)"

<xsl:variable name="base-type-local-name" 
select="local-name-from-QName($base-type-qname)"/> 

<xsl:variable name="base-type-namespace-uri" 
select="namespace-uri-from-QName($base-type-qname)"/>

<xsl:variable name="type-local-name" select="xs:schema/xs:simpleType[1]/@name"/>
<xsl:variable name="type-namespace-uri" select="xs:schema/@targetNamespace"/>

<xsl:variable name="basetype-is-type" select="if ( $base-type-local-name = 
$type-local-name" and $base-type-namespace-uri = $type-namespace-uri)
then true
else false"/>


Lisa


--- On Fri, 4/8/11, Costello, Roger L. <costello(_at_)mitre(_dot_)org> wrote:

From: Costello, Roger L. <costello(_at_)mitre(_dot_)org>
Subject: [xsl] How to compare two QName values in an XML Schema?
To: "xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com" 
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Received: Friday, April 8, 2011, 11:00 AM
Hi Folks,

Below is an XML Schema, containing two simpleTypes. The
second one references the first.

I want an XPath expression that compares the second
simpleType's reference to the name of the first simpleType:


    /xs:schema/xs:simpleType[1]/@name 
      eq 
   
/xs:schema/xs:simpleType[2]/xs:restriction/@base


That returns False. I want it to return True. 

I figured the reason it's returning False is because it is
comparing the string "elev:BostonAreaSurfaceElevation"
against the string "EarthSurfaceElevation". Yes?

I want it to do a comparison of QNames, not strings. So I
type-cast the values:


    xs:QName(/xs:schema/xs:simpleType[1]/@name) 
       eq 
   
xs:QName(/xs:schema/xs:simpleType[2]/xs:restriction/@base)


But that gave me this error:

   Casting from xs:unTypedAtomic to xs:QName
can never succeed.

Why?

What's the correct way to do the comparison?

---------------------------------------------------------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
           
targetNamespace="http://www.elevation.org";
            xmlns:elev="http://www.elevation.org";
           
elementFormDefault="qualified"> 

    <xsd:simpleType name=
"EarthSurfaceElevation">
        <xsd:restriction
base="xsd:integer">
           
<xsd:minInclusive value="-1290"/>
           
<xsd:maxInclusive value="29035"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:simpleType name=
"BostonAreaSurfaceElevation">
        <xsd:restriction
base="elev:EarthSurfaceElevation">
           
<xsd:minInclusive value="0"/>
           
<xsd:maxInclusive value="120"/>
        </xsd:restriction>
    </xsd:simpleType>
    
</xsd:schema>
---------------------------------------------------------

/Roger

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--