xsl-list
[Top] [All Lists]

RE: [xsl] Namespace(?) question

2007-03-07 08:30:53
If you make this a schema-aware transformation in XSLT 2.0 (using the
schema-for-schemas to validate the input document) then you can define a key
on your complex types like this:

<xsl:key name="ct" match="/xs:schema/xs:complexType"
use="QName(/schema/@targetNamespace, @name)"/>

and you can then retrieve them like this:

key('ct', @type)

(assuming they are defined in the same schema document, which is not really
something you should assume...)

This works because the XSLT processor knows that @type is a QName, because
the schema says so, and it will automatically resolve the prefix part of the
QName using the in-scope namespaces.

If you're not using schema-aware processing, then the system has no
knowledge that the attributes are QNames, and you're going to have to sort
out the name matching by hand. If you're only looking for types defined in
the same schema document then you can ignore the prefix, so it's not that
difficult.

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: sthomas2(_at_)ups(_dot_)com [mailto:sthomas2(_at_)ups(_dot_)com] 
Sent: 07 March 2007 14:08
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Namespace(?) question


Sorry to bother everyone with a question whose answer is 
probably in the FAQ, but I couldn't find it there.

My input document (which happens to be a schema) has the 
following form:


<xs:schema
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 xmlns:pfx="http://my.url";
 targetNamespace="http://my.url";
 elementFormDefault="qualified">

  <xs:complexType name="ChildClass">
    <!-- details omitted ->
  </xs:complexType>

  <xs:element name="ParentClass">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Property" type="pfx:ChildClass"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

 
As part of its processing, my transform needs to identify all 
complexType nodes that are referenced as types elsewhere in 
the document. In the example above, I need to identify 
ChildClass because it is a complexType that is referenced by 
the "type" attribute within the ParentClass.

I would expect the following to work:

<xsl:template match="/">
  <xsl:for-each
select="(*/xs:simpleType|*/xs:complexType)[//@type=(_at_)name]">
    <!-- do something useful ->
  </xsl:for-each>
</xsl:template>


But, at least with Saxon6.5.5 it selects nothing. It seems 
like a namespace problem, since removing pfx: from the type 
(and defining a default namespace) makes the transform work 
as I expect it to. I suppose I could play around with 
local-name() and get the transform to work, but that doesn't 
seem like the right approach. I was thinking (hoping?) that 
XSL would handle the namespace resolution automatically, but 
clearly I am wrong. Or perhaps my select is wrong, and it 
just happens to work by coincidence without namespace 
prefixes. In any case, I would welcome enlightenment.

Many thanks for your patience and thanks in advance for any 
assistance,

Stephen



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>