[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Namespace declaration and schema validation problems


schema validation namespace
[Noelle]

> First of all, I have an XML page, which is uses XSLT to transform into
XHTML
> (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
browser
> (IE6) or is there something else I should need to add.  Despite having
read
> 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
thing.

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.

Cheers,

Tom P


> The second problem involves my schema.  Although the schema and XML
validate
> against each other
> when I use a schema validator, the XML doesn't seem to be validating
against
> 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
if
> someone adds their own XML document that it's valid (I'm using ASP and
have
> 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>
>
>



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.