Momo
Momo

Reputation: 484

See all declared elements in an XML-Namespace

Is it possible to read out all possible elements in a XML-Namespace? I want that to create a auto complete function for my own XSLT-Editor. I can't find anything if this is possible, but how does a XslCompiler know what elements are declared in a namespace and which are not?

And of course i know there a documentations somewhere on the internet where you can see the functions of a namespace, but i want to read it out programaticly. Is that possible?

For example the namepace http://www.w3.org/1999/XSL/Transform i want to know which elements/functions are declared: like => function / value-of / choose etc.

Upvotes: 0

Views: 53

Answers (3)

Michael Kay
Michael Kay

Reputation: 163549

Answering this part of your question:

But how does a XSLT Compiler know about the functions and elements in there?

Let's ignore functions for now and focus on elements. In general, the XSLT compiler doesn't know what names can appear. It assumes that all names are valid.

If you write a schema-aware stylesheet using

<xsl:import-schema schema-location="some.xsd"/>

then the XSLT processor will check your XSLT code for consistency with the XSD schema, and may give you warnings (or in some cases errors) if you use names that cannot possibly select anything. This only works if (a) the namespace is described by an XSD schema, (b) you use a schema-aware processor, (c) you tell the XSLT processor where to find the schema, and (d) you indicate in your stylesheet which template rules are constrained to match validated documents (in XSLT 3.0 you can do this conveniently with <xsl:mode typed="strict"/>.

As for functions, the functions available to your stylesheet are a mix of system-defined and user-defined functions. Essentially, the available functions are the standard built-in functions plus those declared in the stylesheet itself.

Upvotes: 1

Quentin
Quentin

Reputation: 944170

Is it possible to read out all possible elements in a XML-Namespace?

Not in the general case.

A namespace is just an identifier. There is no enforced system for describing what elements and addresses are used in it.

There might be a schema which describes that. There might be a DTD that describes that. There might be a RELAX NG that describes it. There might be a Schematron that describes it. There might be a natural language document that describes it. There might be no documentation at all.

There's also no standard way to link a schema to its documentation (remember that while schema identifiers look like HTTP URLs, they aren't really).

Upvotes: 1

Martin Honnen
Martin Honnen

Reputation: 167716

If you visit https://www.w3.org/1999/XSL/Transform in your browser then it explains that there are now three versions of XSLT, 1.0 and 2.0 and 3.0 and it links to schemas or DTDs for the different versions, for instance for the latest version XSLT 3.0 you will find a link to an XSD schema https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd and also to an Relax-NG schema https://www.w3.org/TR/xslt-30/schema-for-xslt30.rnc. You can read such schemas programmatically with various APIs/schema object models, depending on your language/framework to find out declared elements and attributes.

Upvotes: 0

Related Questions