Missing xmlns attribute while indenting using xalan (JAVA)

H

Hyunchan Kim

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?
 
M

Martin Honnen

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top