empty namespace
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 31
- Joined: Sat Apr 16, 2005 11:29 am
empty namespace
Hi,
Hope you can help me this...
I have the following XML:
and the following XSL:
the output looks like:
my questions:
why do i have the empty xmlns attribute?
and
how can i prevent this?
Thanks, Hans Scholte
Hope you can help me this...
I have the following XML:
Code: Select all
<?xml version="1.0"?>
<result>
<A ID="oai:ARNO:148242" DT="2005-03-02"/>
<A ID="oai:ARNO:148374" DT="2005-03-04"/>
</result>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<feed xmlns="http://www.w3.org/2005/Atom">
<xsl:apply-templates/>
</feed>
</xsl:template>
<!-- -->
<xsl:template match="result">
<xsl:apply-templates/>
</xsl:template>
<!-- -->
<xsl:template match="A">
<entry>
<xsl:apply-templates/>
</entry>
</xsl:template>
<!-- -->
<xsl:template match="* | @*"/>
<!-- -->
</xsl:stylesheet>
the output looks like:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry xmlns=""/>
<entry xmlns=""/>
</feed>
why do i have the empty xmlns attribute?
and
how can i prevent this?
Thanks, Hans Scholte
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Hans,
You generate as output a feed element in the http://www.w3.org/2005/Atom namespace and inside thie element you generate entry elements from no namespace. In order to represent that as XML, if a default namesapce declaration is used to represent feed then the default namespace must be reset to no namepsace to represent entry correctly. If you want your entry elements also in the http://www.w3.org/2005/Atom namespace then place them in that namespace:
<entry xmlns="http://www.w3.org/2005/Atom">
...
Best Regards,
George
You generate as output a feed element in the http://www.w3.org/2005/Atom namespace and inside thie element you generate entry elements from no namespace. In order to represent that as XML, if a default namesapce declaration is used to represent feed then the default namespace must be reset to no namepsace to represent entry correctly. If you want your entry elements also in the http://www.w3.org/2005/Atom namespace then place them in that namespace:
<entry xmlns="http://www.w3.org/2005/Atom">
...
Best Regards,
George
-
- Posts: 31
- Joined: Sat Apr 16, 2005 11:29 am
Hi George
I can follow you there but, when a output a title elements in the xslt (one in <feed> and one in <entry> then these do not have a namespace attribute. Like:
Why is that?
Thank, Hans
I can follow you there but, when a output a title elements in the xslt (one in <feed> and one in <entry> then these do not have a namespace attribute. Like:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>this doesn't have the namespace attribute</title>
<entry xmlns="">
<title>this one neither</title>
</entry>
</feed>
Thank, Hans
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Hans,
The namespaces are inherited from parent and inside entry no prefix means no namespace and if you output a title element from no namespace there is no need to declare again the default namespace as no namespace as the default namespace is already no namespace being delcared so in entry with the xmlns="" namespace declaration.
Best Regards,
George
The namespaces are inherited from parent and inside entry no prefix means no namespace and if you output a title element from no namespace there is no need to declare again the default namespace as no namespace as the default namespace is already no namespace being delcared so in entry with the xmlns="" namespace declaration.
Best Regards,
George
-
- Posts: 89
- Joined: Mon Mar 06, 2006 10:13 pm
An element automatically falls under the same namespace as it's parent unless stated otherwise by declaring a different namespace.
Additionally, if you wanted all elements in your output to have the same namespace you could move the xmlns attribute to your xsl:stylesheet element, eg.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/2005/Atom">
Additionally, if you wanted all elements in your output to have the same namespace you could move the xmlns attribute to your xsl:stylesheet element, eg.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/2005/Atom">
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service