[xsl] processing xml data with default namespace

Subject: [xsl] processing xml data with default namespace
From: Achim Staebler <achim@xxxxxxxxxxxx>
Date: Wed, 12 Jul 2006 21:04:11 +0200
hey list,

i'm trying to process xml data that has a default namespace:

<--- snip: test.xml --->
<?xml version="1.0" encoding="utf-8"?>
<foo xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
	 xmlns="http://www.patexpert.org/ont/metaont#";>
	<bar rdf:about="#id">argh</bar>
</foo>
<--- snip --->


processing this data with the stylesheet


<--- snip: test1.xsl --->
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
		xmlns:pat="http://www.patexpert.org/ont/metaont#";
		exclude-result-prefixes="pat"
		version="2.0">

<xsl:output method="xml" version="1.0" indent="yes" encoding="utf-8" />

	<xsl:template match="pat:foo">
		<xsl:element name="bar"
		namespace="http://www.patexpert.org/ont/metaont#";>
		</xsl:element>
	</xsl:template>

</xsl:stylesheet>
<--- test1.xsl --->

yields the (expected) result

<--- snip:output1 --->
<?xml version="1.0" encoding="utf-8"?>
<bar xmlns="http://www.patexpert.org/ont/metaont#"/>
<--- snip --->

i was trying to replace the xsl:element tags with a more direct

<--- snip:test2.xsl --->
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
		xmlns:pat="http://www.patexpert.org/ont/metaont#";
		exclude-result-prefixes="pat"
		version="2.0">

<xsl:output method="xml" version="1.0" indent="yes" encoding="utf-8" />

	<xsl:template match="pat:foo">
		<pat:bar>
		</pat:bar>
	</xsl:template>

</xsl:stylesheet>
<--- snip --->

but i am getting

<--- snip: output2 --->
<?xml version="1.0" encoding="utf-8"?>
<pat:bar xmlns:pat="http://www.patexpert.org/ont/metaont#"/>
<--- snip --->

i was expecting to get the same result as in output1. why is pat:bar apparently not the same as the xsl:element instruction above?

thanks,

achim.

Current Thread