This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ignore namespaces


Hi Filipe,

> I have a pretty complex XSL prepared to work with an XML input
> without namespaces.
>
> Now I want to use an XML document with namespaces in some of its
> elements but those namespaces should be ignored by the XSL and the
> elements processed as if no namespace existed.
>
> Is there an easy way to do this?

Unfortunately not in XSLT 1.0. As far as XPath and XSLT are concerned,
an element with a namespace is completely different from an element
without a namespace. To change an XSLT 1.0 stylesheet from working
over a source document without namespaces to one with, you have to
change every XPath that refers to elements that now have a namespace,
so that they include prefixes pointing to that namespace.

Because this is a common problem, XSLT 2.0 has an attribute,
'default-xpath-namespace', which you can use to tell the XPath
processor that any element name tests without prefixes in XPaths
should count as selecting/matches elements in that default XPath
namespace rather than in no namespace. So come XSLT 2.0 you'll be able
to just slide your new namespace into that attribute and everything
(well, assuming that *all* your elements were in that namespace) would
work fine.

> Perhaps the best would be to make some sort of pre-processing and
> remove all namespaces before applying the XSL.
>
> I'm trying to avoid changing the way my XSL works because I guess it
> won't be that easy (or maybe it is...?)

If you want to carry on being able to process the original documents,
that didn't have a namespace, then a pre-processing step would be
sensible (and isn't hard to do in XSLT). If you now *only* want to use
the documents with namespaces as the source, you may as well change
the XPaths; it'll probably be simpler in the long run, and more in the
spirit of the namespace use.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]