473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 9878
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: mickjames | last post by:
Hi, I'd like to include the whole web page content (as opposed to just the headlines) into RSS/XML to enable people to read them via rss feed readers. Question: how to convert HTML elements...
17
by: Colin Cogle | last post by:
------- Line 47, column 8: there is no attribute "id" <DIV id="LeftNavigation" style="position:absolute; left:8px; top:6px; width:200p ------- Line 47, column 31: there is no attribute "style"...
4
by: Glenn | last post by:
Help I'm trying to perform a transform and I keep on getting '' is invalid QName. The weird thing is, I can take the same code, stylesheet and XML, put into a Console app and it works okay. ...
3
by: Daylor | last post by:
hi. i got a sample project written in vc6. when i compile and build the exe (debug mode ) , the exe file size is 221KB, and the program work ok. if i open this project in vc7 , build the exe,...
1
by: mdawoodk | last post by:
i am getting error "input string was not in correct format" when converting a string decimal into integer value. code is like this: string strVal = ""; int nVal = 0; strVal = "14.9"; nVal...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
0
Krishna Ladwa
by: Krishna Ladwa | last post by:
In Sql Server 2000 Version, I found that no Notification message box appears when converting text column to varchar but the data gets truncated to the given size for the varchar. Whereas it appears...
2
by: clintonb | last post by:
Victor said: The double value that I'm trying to convert to GCSMoney (which is implemented as cents) was produced by multiplying a dollar amount by an interest rate to get interest. double...
5
by: Joell | last post by:
When I try to insert values into an existing table, I am getting the following error. The table is not in bit data type format and neither is the target table. Conversion failed when converting the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.