Missing xmlns attribute while indenting using xalan (JAVA)

Hyunchan Kim

Usenet Archive
Joined
Dec 18, 2003
Messages
1
Reaction score
0
To indent xml file, I made an instance of Transformer from Templates using following.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" version="1.0"> <xsl:eek:utput method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>

The transform seems to work fine, most of the cases. But if I call transform above XML as an input, output has only one xmlns attribute like this.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xalan="http://xml.apache.org/xslt"
version="1.0">
<xsl:eek:utput method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>

Following attribute is lost...
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

If I modify "xmlns:xsl" to "mlns:xsl" (delete first character to see what happens), output is correct i.e, root element has two attributes including mlns:xsl="http://www.w3.org/1999/XSL/Transform"

I have read some reference materials to find out what's wrong. But I can't find any problem. As I know so far, <xsl:template match="/"> means root of DOM tree and <xsl:copy-of select="."/> means copy that to target document.

So, I think everything should go fine...

Does anyone know what's wrong?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Hyunchan said:
To indent xml file, I made an instance of Transformer from Templates using following.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" version="1.0"> <xsl:eek:utput method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>

The transform seems to work fine, most of the cases. But if I call transform above XML as an input, output has only one xmlns attribute like this.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xalan="http://xml.apache.org/xslt"
version="1.0">
<xsl:eek:utput method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>

Following attribute is lost...
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

If I modify "xmlns:xsl" to "mlns:xsl" (delete first character to see what happens), output is correct i.e, root element has two attributes including mlns:xsl="http://www.w3.org/1999/XSL/Transform"

I have read some reference materials to find out what's wrong. But I can't find any problem. As I know so far, <xsl:template match="/"> means root of DOM tree and <xsl:copy-of select="."/> means copy that to target document.

So, I think everything should go fine...

Does anyone know what's wrong?

Well, the namespace http://www.w3.org/1999/XSL/Transform has to be declared in every stylesheet but should not be output normally so it is tricky to have it included. I don't have a solution currently, maybe you can find something in the XSL FAQ:
http://www.dpawson.co.uk/xsl/sect2/N5536.html#d5360e1276
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top