Subject: [xsl] xsl] Random Namespaces Declared with XSLT Stylesheet... why? From: Joseph Kesselman <keshlam@xxxxxxxxxx> Date: Thu, 19 Jun 2003 12:33:13 -0400 |
>The stylesheet seems to randomly put namespace declarations >where they're not needed. I haven't dug into the specific example, but some general thoughts on what you may be seeing: "Needed" is determined by sevaral factors. One is that the prefix is being used in an output element or attribute and isn't already bound to the correct namespace in that context. In this case, of course, failing to do so would yield an incorrect result document. But namespace declarations may also be produced when a namespace node is copied from the source document or stylesheet to the output (though again, they may be suppressed if a correct prefix binding is already in scope). And when an element is copied into the output document, it's namespace nodes come with it; see 7.1.1 and 7.5 in the XSLT 1.0 spec. This behavior is not optional or conditional... and in order to make sure a namespace node exists in the output document, Xalan (and any other XSLT processor) has to generate a declaration. If you want to spend the effort, you can have Xalan output SAX and write your own logic which attempts to filter out namespace nodes which aren't being used before routing the SAX stream to a serializer. I don't recommend doing so. Determining whether a namespace declaration is required by a subtree would require that you buffer that tree in memory while this is determined, which would have significant performance impact. The filtering determination becomes even more expensive if the prefix might be used in content rather than in a QName -- in an XPath, for example -- since you're now talking about walking through all the string content character-by-character. Or you can avoid copying elements and instead explicitly regenerate them with <xsl:element/>. But then it then becomes your responsibility to make sure any namespace nodes that are requried are generated, and XSLT 1.0 doesn't have a clean way of explicitly adding a namespace node. (XSLT 2.0 has a proposal to fix that.) The usual solution is to shurg and accept that declarations for unused prefixes are ugly but mostly-harmless. ______________________________________ Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more. "The world changed profoundly and unpredictably the day Tim Berners Lee got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] testing for text in one o, Passin, Tom | Thread | [xsl] Fw: omitting empty elements w, Venkat Gyambavantha |
RE: [xsl] testing for text in one o, Passin, Tom | Date | Re: RE: [xsl] grouping by unique..., Vasu Chakkera |
Month |