[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|