468,771 Members | 1,481 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

XSLT returning '' is an invalid QName when converting Attributes to Elements

Hi

I have created two flavors of an XSLT stylesheet to transform all attributes
of an XML document to elements:
They both work as expected with MSXML and XMLSPY but throw an exception

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- handle all child nodes plus
attributes -->

<xsl:apply-templates select="node() |
@*"/>

</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->

<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

<!-- template for converting attributes to elements -->

<xsl:template match="@*">

<xsl:element name="{local-name()}"
namespace="{namespace-uri()}">

<xsl:value-of select="."/>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- converting attributes to
elements -->

<xsl:for-each
select="attribute::node()">

<xsl:element
name="{local-name()}" namespace="{namespace-uri()}">

<xsl:value-of
select="."/>

</xsl:element>

</xsl:for-each>

<xsl:apply-templates select="node()" />

</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->

<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

</xsl:stylesheet>

=========================

The problem is that the local-name() function always returns an empty string
which results in the error message

'' is an invalid QName

Is this a bug in the framework?

Jim
Nov 12 '05 #1
3 9016
I could not reproduce the problem (transformed with the Framework 1.0, 1.1
and 2.0).

Could you, please, provide the source xml document the transformation of
which results in the described error messages?
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"Stephan Brunner" <s_*****@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
Hi

I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements:
They both work as expected with MSXML and XMLSPY but throw an exception

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- handle all child nodes plus
attributes -->

<xsl:apply-templates select="node() |
@*"/>

</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->

<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

<!-- template for converting attributes to elements -->

<xsl:template match="@*">

<xsl:element name="{local-name()}"
namespace="{namespace-uri()}">

<xsl:value-of select="."/>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- converting attributes to
elements -->

<xsl:for-each
select="attribute::node()">

<xsl:element
name="{local-name()}" namespace="{namespace-uri()}">

<xsl:value-of
select="."/>

</xsl:element>

</xsl:for-each>

<xsl:apply-templates select="node()" />
</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->

<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

</xsl:stylesheet>

=========================

The problem is that the local-name() function always returns an empty string which results in the error message

'' is an invalid QName

Is this a bug in the framework?

Jim

Nov 12 '05 #2
I too have had success with local-name() in my XSLT.

If it is any help, I was able to run your XSLT on some XML documents without
any errors. I'd be curious to see if the problem is specific to the
document you are working with.

Also, try using a standard utility like nxslt
(http://www.tkachenko.com/dotnet/nxslt.html) & check if you are still
getting the error.

-----
"Stephan Brunner" <s_*****@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
Hi

I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements:
They both work as expected with MSXML and XMLSPY but throw an exception

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- handle all child nodes plus
attributes -->

<xsl:apply-templates select="node() |
@*"/>

</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->

<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

<!-- template for converting attributes to elements -->

<xsl:template match="@*">

<xsl:element name="{local-name()}"
namespace="{namespace-uri()}">

<xsl:value-of select="."/>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- converting attributes to
elements -->

<xsl:for-each
select="attribute::node()">

<xsl:element
name="{local-name()}" namespace="{namespace-uri()}">

<xsl:value-of
select="."/>

</xsl:element>

</xsl:for-each>

<xsl:apply-templates select="node()" />
</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->

<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

</xsl:stylesheet>

=========================

The problem is that the local-name() function always returns an empty string which results in the error message

'' is an invalid QName

Is this a bug in the framework?

Jim

Nov 12 '05 #3
Hi

I used the ObjectXPathNavigator to serialize an object to XML
This code is very useful when you want to write out ReadOnly attributes
which XML serialization is unable to handle.

see:
http://msdn.microsoft.com/library/de...ml03172003.asp
The code works if no transformation is used when accessing the
XPathNavigator.
But as soon as the beforementioned transformation is used there is a problem
if a node has no attributes but has child nodes with attributes.
It's simply a bug in the sample code.

Took me about 5 hours of debugging to track this one down :-)

Sorry
Stephan
"NaraendiraKumar R. R." <na********@nospam.com> wrote in message
news:es*************@TK2MSFTNGP10.phx.gbl...
I too have had success with local-name() in my XSLT.

If it is any help, I was able to run your XSLT on some XML documents without any errors. I'd be curious to see if the problem is specific to the
document you are working with.

Also, try using a standard utility like nxslt
(http://www.tkachenko.com/dotnet/nxslt.html) & check if you are still
getting the error.

-----
"Stephan Brunner" <s_*****@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
Hi

I have created two flavors of an XSLT stylesheet to transform all

attributes
of an XML document to elements:
They both work as expected with MSXML and XMLSPY but throw an exception

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- handle all child nodes plus
attributes -->

<xsl:apply-templates select="node() | @*"/>

</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->
<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

<!-- template for converting attributes to elements -->

<xsl:template match="@*">

<xsl:element name="{local-name()}"
namespace="{namespace-uri()}">

<xsl:value-of select="."/>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

=========================
<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="*">

<!-- copy of the element itself -->

<xsl:copy>

<!-- converting attributes to
elements -->

<xsl:for-each
select="attribute::node()">

<xsl:element
name="{local-name()}" namespace="{namespace-uri()}">

<xsl:value-of select="."/>

</xsl:element>

</xsl:for-each>

<xsl:apply-templates select="node()"

/>

</xsl:copy>

</xsl:template>

<!-- template for copying over text, comment and pi nodes -->
<xsl:template match="text() | comment() |
processing-instruction()">

<xsl:copy/>

</xsl:template>

</xsl:stylesheet>

=========================

The problem is that the local-name() function always returns an empty

string
which results in the error message

'' is an invalid QName

Is this a bug in the framework?

Jim


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by mickjames | last post: by
4 posts views Thread by Glenn | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.