bug with <x:copy> on namespaced attributes

Here should go questions about transforming XML with XSLT and FOP.
wpsboy
Posts: 2
Joined: Mon Dec 26, 2005 12:35 pm

bug with <x:copy> on namespaced attributes

Post by wpsboy » Mon Dec 26, 2005 12:54 pm

hi,

i've some issue with xsl transform when i'm using <x:copy> tag.
I don't know if it is a know bug or if i do something wrong.

It seem like Xalan processor can't copy namespaced attributes.
I've give an example for more understanding.

My xml File

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xsl.xsl" type="text/xsl"?>

<tag xmlns:test1="namespace" test2="noNamespace" />
My xsl File (xsl.xsl)

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/tag">
<xsl:copy>
namespaced attribute : <xsl:apply-templates select="@xmlns:test1"/>
</xsl:copy>
|||
<xsl:copy>
normal attribute : <xsl:apply-templates select="@test2"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Result in browser

Code: Select all


namespaced attribute : ||| normal attribute : noNamespace
anyone can help ??


Thanks in advance

Fabrice.

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Tue Dec 27, 2005 10:54 am

Hi Fabrice,

The namespace declarations look like attributes but they are not attributes. In fact I cannot get your sample stylesheet to work neither with Xalan nor with Saxon.
You can access the namespace declarations on the namespace axis like below:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/tag">
namespaces:
<xsl:for-each select="namespace::*">
[<xsl:value-of select="."/>]
</xsl:for-each>

test2:<xsl:value-of select="@test2"/>
</xsl:template>
</xsl:stylesheet>
This will give you

Code: Select all



namespaces:

[http://www.w3.org/XML/1998/namespace]

[namespace]


test2:noNamespace
Best Regards,
George

wpsboy
Posts: 2
Joined: Mon Dec 26, 2005 12:35 pm

Post by wpsboy » Wed Dec 28, 2005 1:22 pm

thanks george for reply!

I've now more understanding about namespace.

but that 's not resolve my issue.

I think it is really a bug...

I will try to do copy by hand.
Do you know how to insert < or > charactere to output ?

Best regards,

Fabrice.

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Wed Dec 28, 2005 3:07 pm

Hi,

Use [ code ] and [ / code ] without spaces to enclose the content you want to post.

Code: Select all


<>

Best Regards,
George

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Wed Dec 28, 2005 3:12 pm

Sorry :)
It seems you want to output < and > as the XSLT output...
You can just write them as any other characters and they will be encoded in the output. However, if the output is XML they will be escaped, if the output is text they will appear as they are.

Best Regards,
George

Post Reply