Template gets applied where it shouldn't...

I'm trying to parse a schema into an input form.

So I have a template like this:

<xsl:template match="xs:element" mode="schemaTop">

<xsl:value-of select="@type"/>

</xsl:template>

Which is only called from <xsl:template match="/xs:schema">

.

So you would think that it would only match the root xs:element of the schema right? But instead it matches children and some grand-children of xs:schema, like the ones inside the first complexType definition. Shouldn't "xs:element" only match children of "xs:schema"?

The schema is:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root" type="rootType"/>

<xs:complexType name="rootType">

<xs:sequence>

<xs:element name="one" type="oneType"/>

<xs:element name="two" type="twoType"/>

<xs:element name="three" type="threeType"/>

</xs:sequence>

</xs:complexType>

<xs:complexType name="oneType">

<xs:sequence>

<xs:choice>

<xs:element name="aString" type="xs:string"/>

<xs:element name="aNumber" type="xs:nonNegativeInteger"/>

</xs:choice>

</xs:sequence>

</xs:complexType>

<xs:complexType name="twoType">

<xs:sequence>

<xs:element name="something" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>

<xs:element name="somethingElse" type="xs:string" minOccurs="0" maxOccurs="3"/>

</xs:sequence>

</xs:complexType>

<xs:complexType name="threeType">

<xs:sequence>

<xs:element name="aThing" type="xs:string" minOccurs="0" maxOccurs="4"/>

<xs:element name="anotherThing" type="xs:string" minOccurs="0" maxOccurs="4"/>

<xs:element name="yetAnother" type="xs:string" minOccurs="0" maxOccurs="2"/>

</xs:sequence>

</xs:complexType>

</xs:schema>

And the output I get is (right now the template only prints the element type and doesn't print anything else):

rootType

oneType

twoType

threeType

[3278 byte] By [iamnoaha] at [2007-9-23]
# 1

You forgot about XSLT's built-in template rules, I think. If<xsl:template match="/xs:schema">calls <xsl:apply-templates> then the built-in template rules (which do nothing for elements but call xsl:apply-templates) will apply to your xs:complexType and xs:sequence elements and thus your own template will apply to the xs:element children of the xs:sequence elements.

DrClapa at 2007-7-11 > top of java,Enterprise & Remote Computing,Enterprise Technologies...