1

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)

mo.
  • 3,474
  • 1
  • 23
  • 20

2 Answers2

1

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

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

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

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.

Community
  • 1
  • 1
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • the element name is not bound to the type, its just a representation in a tree: complexType name="Record" ... element name="x" type="Record", element name="y" type="Record". both are Records. in my situation i cannot use the element name because i dont know it. – mo. May 12 '10 at 10:12
  • You may need to post your actual XML before we understand what you're asking. I'm lost, frankly. – Matt Gibson May 12 '10 at 10:22
  • Still not sure, but visit the link to see if it helps at all. – GSerg May 12 '10 at 13:16