Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Optional namespace declaration in XML document

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 5/1/2006 3:04:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent