[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Optional namespace declaration in XML document


Subject: RE: [xsl] Optional namespace declaration in XML document
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 01 May 2006 11:02:55 -0400

At 2006-05-01 15:38 +0100, Fraser Goffin wrote:
Admittedly this may be inefficient or the document to be processed may be so complex that it may not be practical, but for simple situations it would be ok wouldn't it ?

I guess that depends on your definition of "simple".


The example docs were :-

<mydata xmlns="urn:myns">
        <mydataitem>sample data</mydataitem>
</mydata>

<mydata xmlns="urn:otherns">
        <mydataitem>sample data</mydataitem>
</mydata>

<mydata>
        <mydataitem>sample data</mydataitem>
</mydata>

Wouldn't something like this do ?? :-

<xsl:template match="*[local-name(.) = 'mydata']">
...

<xsl:template match="*[local-name(.) = 'mydataitem']">
...

It would "do" if you equated the three different vocabularies as being the same from an application's perspective of interpreting semantics associated with the vocabularies ... though a preprocessing step of stripping the namespaces would be more efficient.


But I see {urn:myns}mydataitem and {urn:otherns}mydataitem and mydataitem as three distinct labels probably identifying different semantics when implementing my applications detecting those labels.

We use something similar on complex documents where only the top level element is declared as a global type and thus has a namespace affiliation, all other types are local (and the schema declares elementFormDefault='unqualified').

If the element names are not qualified with namespaces, then you can just match as usual ... that's the feature of XPath in XSLT that trips many people up as if they thought it was a bug. When you have:


<xsl:template match="foo">

... you are matching foo in no namespace (not the default namespace).

I would much prefer using that than using:

<xsl:template match="*[local-name()='foo']">

I hope this helps.

. . . . . . . . . . Ken

--
Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
Also for XSLT/XSL-FO training:    Minneapolis, MN 2006-07-31/08-04
Also for XML/XSLT/XSL-FO training:Birmingham,England 2006-05-22/25
Also for XSLT/XSL-FO training:    Copenhagen,Denmark 2006-05-08/11
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


Current Thread
Keywords