[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: with or without namespace
On 11/16/2010 11:33 AM, ac wrote: > Hi, > > I have a xslt2 stylesheet that transforms to (x)html, an XML document > type that comes in two flavors, both with the same "local-name" > elements, but with or without namespace. > > For example, either: > > ... xmlns:xx="aaa.cc"> > <xx:a> > <xx:b>bla</xx:b> > </xx:a> > ... > > or > > ...> > <a> > <b>bla</b> > </a> > ... > > To process these elements irrespective of their namespace, I can use > expressions like > *[local-name(.) = "a"] and *[local-name(.) = "b"] > all through the stylesheet but, in the stylesheet, I would much rather > map everything to the same namespace (possibly to default- or > no-namespace) and either use a single prefix, or better still, no > prefix, all over the stylesheet, to refer to all or any of these > elements. > /xx:a, /xx:b, or /a , /b, for example > What would be the best way to declare the stylesheet namespaces to > achieve this, if possible? > > Thank you, > ac > If you are using XSLT 2.0, you can declare a default namespace to be used in XPath expressions; but that would not help, because you would then be unable to address elements that are in no namespace. I think your best bet is to declare a short prefix (like xx, as you said) for the namespace, and then whenever you need to match "a", use "a|xx:a". There may be some situations where that's awkward or impossible, though... Another alternative would be to add a preliminary transformation that strips namespaces on all elements. Then you can feed the result of that transformation to a stylesheet that can assume the input elements have no namespace. The preliminary transformation can be implemented as a separate stylesheet, or if you have XSLT 2.0 or exslt:node-set(), it can be part of the same stylesheet. Lars
|
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
|