OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Namespace declaration and schema validation problems

[ Lists Home | Date Index | Thread Index ]


> First of all, I have an XML page, which is uses XSLT to transform into
> (with a separate CSS), but it won't render correctly if I include a
> namespace declaration in the top level element.  I don't have a prefix for
> my elements or attributes, so it's just "xmlns".  The text
> of the page displays, but it's completely devoid of any structure or
> formatting. Is the namespace declaration just not recognised by the
> (IE6) or is there something else I should need to add.  Despite having
> up on namespaces, I couldn't find anything to indicate why this is
> happening. The web page renders fine without the declaration, so I can use
> it without it, but I'd like to know why it won't work with it.

This is not too clear, but I assume that you mean that you add a default
namespace declaration to the xml document, like
xmlns='http://www.example.com', and that the result you are seeing is the
result of an xslt transformation.  If so, this is a well-known xpath/xslt

In your stylesheet, you will have some templates that select nodes, like
select='para'.  When  you use a default namespace, all your elements are in
a namespace (the default namespace), but your templates are trying to select
and match elements that are in no namespace.  So no templates ever match,
and the processor falls back on using the built-in default templates, which
match all the text content.

The remedy is simple.  To the xslt stylesheet element, add a namespace for
the same URI as the default namespace in your source.  It does not matter
what prefix you assign, but it must have a prefix in the stylesheet (you do
not have to change the source).  Then use the prefix in all your select and
match expressions.  For example, now you would write  select='xxx:para", if
you chose the prefix to be "xxx".

Note that the stylesheet will only give the desired results if your source
document uses the namespace expected by the stylesheet.  So you cannot just
go changing it from one document to the next.

Also note that the output will now have a namespace declaration for this new
namespace, and all the output elements will be prefixed.  If you do not
fancy that, go read up on how to suppress specific namespaces in the output.
There are FAQs online, or read Mike Kay's book.


Tom P

> The second problem involves my schema.  Although the schema and XML
> against each other
> when I use a schema validator, the XML doesn't seem to be validating
> the
> schema when I use the browser to view it.  Is it necessary to
> use a DTD as well as a schema to enforce the structure of the document?  I
> would prefer to avoid the DTD since it's less flexible and I had hoped to
> design the schema to allow other users to add their own elements later, if
> needed (in specific parent elements).  However, I want to make sure that
> someone adds their own XML document that it's valid (I'm using ASP and
> set it up so that new XML sections can be added to the database).
> If anyone can offer any clarification on these issues regarding namespace
> and schema use when designing XML web pages, I'd very much appreciate it.
> -Noelle
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> The list archives are at http://lists.xml.org/archives/xml-dev/
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS