Viswanath M
Viswanath M

Reputation: 11

How do I access an element of 'Other" namespace in XS

Sample Schema:

<xs:complexType name="ClassTest">
    <xs:element name="Name" type="xs:string" />
 <xs:element name="Class" type="xs:string" />
 <xs:any namespace="##other" processContents="lax"maxOccurs="Unbound" />

Sample XML:

<ClassTestxmlns="http://schooltest.com">
 <Name>AAA</Name>
 <Class>3</Class>
 <ns:maths>33</ns:maths>
 <ps:english>44<ps:english>
</ClassTest>

How do I refer the elements maths and english which have different namespace to target namespace?

Thanks.

Upvotes: 1

Views: 73

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167716

As your question is tagged as XSLT 2.0, you could also consider to use a wildcard e.g. *:maths and *:english, that selects elements with local name maths respectively english in any namespace.

Upvotes: 2

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243549

How do I refer the elements maths and english which have different namespace to target namespace.

Because nothing is known in advance about the namespace and name of such an element, it is only safe to select them without using any particular name or namespace:

/x:ClassTest/*[not(self::x:Name or self::x:Class)]

Where the prefix "x:" must be bound to the namespace "http://schooltest.com" .

This expression selects any element that is a child of the top element x:ClassTest and is not one of the elements x:Name or x:Class. When applied on the provided XML document, it selects both the ns:maths and the ps:english elements.

Upvotes: 0

Related Questions