mo.
mo.

Reputation: 3544

XSLT Type Checking

Is it possible to check an elements ComplexType?

i have this (simplified):

complexType Record
complexType Customer extension of Record
complexType Person extension of Record 

<xsl:template match="/">
    <records>
    <xsl:apply-templates /> 
    </records>
</xsl:template>

<xsl:template match="!!! TYPECHECK FOR RECORD !!!" name="Record">
   <record><xsl:value-of select="." /></record>
</xsl:template>

is it possible to check elementstype incl. inheritence?

i dont know the elements name only that they are a subtype of Record.

schema 1:
   complexType name="Customer"
      extension base="Record"

   element name="customers"
      element name="customer" type="Customer"

schema 2:
   complexType name="Person"
      extension base="Record"

   element name="persons"
      element name="person" type="Person"

schema ?:
   complexType name="UnknownType"
      extension base="Record"

   element name="unknowns"
      element name="unknown" type="UnknownType"

xml 1:
<customers>
   <customer />
   <customer />
</customers>

xml 2:
<persons>
   <person />
   <person />
</persons>

xml ?:
<?s>
   <? />
   <? />
</?s>

the xml input ist custom so i have to match by the type (i think)

Upvotes: 1

Views: 882

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243579

In XPath 2.0 (and this means XSLT 2.0) one can use the instance-of operator:

. instance-of element(*, my:Record)

Upvotes: 1

GSerg
GSerg

Reputation: 78190

I'm not sure what you mean.

Different types have different tag names, and in xslt you should look at those to decide what type a node is.

Making sure a node indeed has a structure prescribed by your logic is not an xslt task. You should validate the document against a schema before passing it to an xslt processor to achieve this.

EDIT

I'm still not sure, but it seems like this question of mine could be of some help.

Upvotes: 0

Related Questions