Subject: [xsl] Re: Getting rid of xmlns="" attributes From: yguaba@xxxxxxxxxxxx Date: Wed, 31 Dec 2003 14:40:19 -0200 |
Hello Erik, On 30 Dec 2003 at 16:22, Allen, Erik wrote: > (...) I've found that if I change the namespace in the > <xsl:stylesheet> from xmlns to xmlns:y, then I don't get the rogue > attribute, but that is also giving me the incorrect namespace. The > source XML does not have any namespaces defined within it, and I think > that I read somewhere that the <xsl:copy-of> might have issues with > that. Is there anyway to get the namespaces to come out correctly, > without giving me the xmlns=""? You're getting excellent assistance from Lars, but perhaps you're like me and have some trouble understanding the nitty-gritty of namespaces? If so, the excerpt below may help you. Happy new year, Erik Fleischer ------------------------ [Skonnard, Aaron & Gudgin, Martin. (2002) Essential XML Quick Reference: a programmer?s reference to XML, XPath, XSLT, XML Schema, SOAP, and more. Boston: Addison-Wesley, 2002. pp. 3-5.] Because XML allows designers to chose their own tagnames, it is possible that two or more designers may choose the same tagnames for some or all of their elements. XML namespaces provide a way to distinguish deterministically between XML elements that have the same local name but are, in fact, from different vocabularies. This is done by associating an element with a namespace. A namespace acts as a scope for all elements associated with it. Namespaces themselves also have names. A namespace name is a uniform resource identifier (URI). Such a URI serves as a unique string and need not be able to be dereferenced. The namespace name and the local name of the element together form a globally unique name known as a qualified name. Namespace declarations appear inside an element start tag and are used to map a namespace name to another, typically shorter, string known as a namespace prefix . The syntax for a namespace declaration is xmlns:prefix='URI' . It is also possible to map a namespace name to no prefix using a default namespace declaration. The syntax for a default namespace declaration is xmlns='URI' . In both cases, the URI may appear in single quotes ( ' ) or double quotes ( " ). Only one default namespace declaration may appear on an element. Any number of nondefault namespace declarations may appear on an element, provided they all have different prefix parts. It is legal, although not particularly useful, to map the same URI to more than one prefix. All namespace declarations have a scope?that is, a set of elements to which they may apply. A namespace declaration is in scope for the element on which it is declared and all of that element?s descendants. The in-scope mapping of a given prefix to a namespace name can be overridden by providing a new mapping for that prefix on a descendant element. The in-scope default namespace can be overridden by providing a new default namespace declaration on a descendant element. The names of all elements in a document that conforms to the Namespaces in the XML specification are QNames. Syntactically, all QNames have a local name and an optional prefix. Both the local name and the prefix are NCNames. An NCName is a name without a colon in it. The syntax for an element with a prefix is the pre- fix, followed by a colon, followed by the local name. The namespace of an element with a given prefix is the namespace specified by the in-scope namespace declaration for that prefix. It is an error if no such namespace declaration is in scope. The namespace of unprefixed elements is the namespace specified by the in-scope default namespace declaration, if any. If no default namespace declaration is in scope, then such elements are not in any namespace. Elements not in any namespace are known as unqualified elements . The namespace name of unqualified elements is the empty string "" . If a default namespace declaration is in scope and an unqualified element is required, the default namespace declaration can be masked by providing a namespace declaration of the form xmlns='' on the element. Examples Qualified and unqualified elements: <pre:Person xmlns:pre='urn:example-org:People' > <name>Martin</name> <age>33</age> </pre:Person> An element with a local name of Person and a prefix of pre that is mapped to the namespace name urn:example-org:People . The element has children with local names of name and age . Both of these child elements are unqualified; that is, they are not in any namespace. Qualified and unqualified elements using a default namespace declaration: <Person xmlns='urn:example-org:People' > <name xmlns=''>Martin</name> <age xmlns=''>33</age> </Person> An element with a local name of Person and no prefix. The element is in the namespace urn:example-org:People by virtue of an in-scope default namespace declaration for that URI. The element has children with local names of name and age . Both of these child elements are unqualified; that is, they are not in any namespace. This example is equivalent to the previous example. Qualified elements: <pre:Person xmlns:pre='urn:example-org:People' > <pre:name>Martin</pre:name> <pre:age>33</pre:age> </pre:Person> An element with a local name of Person and a prefix of pre that is mapped to the namespace URI urn:example-org:People . The element has children with local names of name and age . Both of these child elements also have a pre- fix of pre and are in the urn:example- org:People namespace. Qualified elements using a default namespace declaration: <Person xmlns='urn:example-org:People' > <name>Martin</name> <age>33</age> </Person> An element with a local name of Person and no prefix. The element is in the namespace urn:example-org:People by virtue of an in-scope default namespace declaration for that URI. The element has children with local names of name and age . Both of these child elements are also in the urn:example-org:People namespace. This example is equivalent to the previous example. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] newbie question on format, Ragulf Pickaxe | Thread | [xsl] Problem Processing Result Tre, Schwartz, Rechell R, |
RE: [xsl] Getting rid of xmlns="" a, Jim Fuller | Date | [xsl] Problem Processing Result Tre, Schwartz, Rechell R, |
Month |