472,802 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 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 9741
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.