Subject: [xsl] [Fwd: Unwanted xmlns attributes in ouput html tags] From: Dinesh Gurram <Dinesh.Gurram@xxxxxxx> Date: Fri, 26 Sep 2003 09:49:43 +1000 |
I am hoping someone may have some ideas to help resolve a problem that I am currently experiencing. It seems rather unique and specific. I am getting unwanted xmlns attributes appearing in output html tags in a two-stage transform process and it appears to be due to the use of includes in the first pass. It also seems to be an xsl-processor-specific problem.
This is a long one, and dare I say, a real toughie (hopefully not for all you experts out there). Please bear with me for the details.
SCENARIO I am using a two stage xsl transform like so: test.ixsl + step_one.xml => intermediate.xsl intermediate.xsl + step_two.xml => final.html (test.ixsl includes an inc.ixsl - a collection of common templates.)
PLATFORM DETAILS Java SDK 1.3.1_08 JAXP 1.1 (crimson 1.1, xalan 2.4.1) I know this is not the latest version but due to reasons beyond my control I am stuck with this combination. Previously I have tried JAXP 1.2 with Java SDK 1.4 and this problem did not occur.
PROBLEM DETAILS During the first transform (ixsl) certain html tags that are to be inserted into "intermediate.xsl" contain xmlns attributes. This screws up the second transform due to namespace issues. The following code example will clarify what I am saying (it is a very simplified, non-sensical example but it does reproduce the problem):
***** test.ixsl: *********** <?xml version="1.0"?> <ixsl:stylesheet version="1.0" xmlns:ixsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias">
<ixsl:namespace-alias stylesheet-prefix="xsl" result-prefix="ixsl" /> <ixsl:output method="xml" encoding="utf-8" />
<xsl:stylesheet version="1.0"> <xsl:template match="/"> <html> <ixsl:call-template name="my_step_one_template" /> <tr/> <xsl:call-template name="my_step_two_template"> <xsl:with-param name="text" select="elements/some_info" /> </xsl:call-template> </html> </xsl:template>
<xsl:template name="my_step_two_template"> <xsl:param name="text" /> <xsl:text disable-output-escaping="yes"><p></xsl:text> <xsl:value-of select="$text" /> <xsl:text disable-output-escaping="yes"></p></xsl:text> </xsl:template> </xsl:stylesheet>
</ixsl:stylesheet> ***** end file *************
***** inc.ixsl: ************ <?xml version="1.0"?> <ixsl:stylesheet version="1.0" xmlns:ixsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias">
<ixsl:namespace-alias stylesheet-prefix="xsl" result-prefix="ixsl" /> <ixsl:output method="xml" encoding="utf-8" />
<ixsl:template name="my_step_one_template"> <tr> <td bgcolor="#666699"> <b> Some text output by step one </b> </td> </tr> </ixsl:template>
</ixsl:stylesheet> ***** end file *************
Note: "ixsl" is the transformation namespace prefix during this stage and the "xsl" namespace is ignored by the processor. However, we use the "namespace-alias" element to swap the xsl and ixsl URIs (ie in the result, "xsl" is assigned the "..../Transform" URI).
The 1st step transformation (test.ixsl + test_data.xml => intermediate.xsl) produces:
***** intermediate.xsl ***** <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:template match="/"><html><tr xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias"><td bgcolor="#666699"><b> Some text output by step one </b></td></tr><tr/><xsl:call-template name="my_step_two_template"><xsl:with-param select="elements/some_info" name="text"/></xsl:call-template></html></xsl:template><xsl:template name="my_step_two_template"><xsl:param name="text"/><xsl:text disable-output-escaping="yes"><p></xsl:text><xsl:value-of select="$text"/><xsl:text disable-output-escaping="yes"></p></xsl:text></xsl:template></xsl:stylesheet> ***** end file *************
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <html> <tr xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias"> <td bgcolor="#666699"><b>Some text output by step one</b></td> </tr> <tr/> <xsl:call-template name="my_step_two_template"> <xsl:with-param select="elements/some_info" name="text"/> </xsl:call-template> </html> </xsl:template>
<xsl:template name="my_step_two_template"> <xsl:param name="text"/> <xsl:text disable-output-escaping="yes"><p></xsl:text> <xsl:value-of select="$text"/> <xsl:text disable-output-escaping="yes"></p></xsl:text> </xsl:template> </xsl:stylesheet>
Notice how the <tr> below <html> has the "xmlns" attribute. Why does this occur? This causes all sorts of havoc.
Another thing to notice is that the "xmlns" attribute does not occur on the <tr/>. If you go back to "test.ixsl" you will see that it was not derived from the included "inc.ixsl". So why does this problem only apply to stuff that's included?
Getting to the final transform (intermediate.xsl + test_data.xml => final.html), it produces:
***** final.html *********** <html> <tr xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias"> <td bgcolor="#666699"><b> Some text output by step one </b></td> </tr> <tr></tr><p></p></html> ***** end file *************
Notice that "my_step_two_template" didn't get called, or at least there is no output from that template in "final.html". My interpretation is that because of the pesky "xmlns" attribute appearing on the <tr> (with the ".../TransformAlias" URI), the processor reads the "xsl:call-template" as being in the "TransformAlias" namespace, hence does not process it, and hence the xsl template is not called.
Something that also puzzles me greatly is why the "TransformAlias" URI is carried over. I am clearly using the "namespace-alias" element correctly as evident from line 2 of "intermediate.xsl" which contains: xmlns:xsl="http://www.w3.org/1999/XSL/Transform". But for some odd reason the <tr> gets the "TransformAlias" URI.
I have used imports instead of includes in the ixsl but that did not make any difference.
The only way I can think of getting around this is to not use includes but in our system, we have a number of ixsl files that require a common set of templates. To do a direct paste of all common templates would create a lot of redundancy and reduce maintainability greatly.
I am well and truly beaten by this problem. Has anyone seen this sort of thing before? Is it a bug? Are there any other solutions or work arounds? Any help will be more than appreciated.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Newbie question: collapse, Wendell Piez | Thread | Re: [xsl] [Fwd: Unwanted xmlns attr, Jeni Tennison |
Re: [xsl] Newbie question: collapse, Wendell Piez | Date | Re: [xsl] Collapse data, Yvonne Wang |
Month |