473,399 Members | 4,192 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,399 software developers and data experts.

XslTransform throws exception when output is an XML fragment

I have an application where I create an xml fragment using
an XslTransform object. However, if I use the following
output method,

<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="no" omit-xml-declaration="yes" standalone="no" />

some of my transforms fail with the following exception:

System.Xml.Xsl.XsltException: There are multiple root
elements in the output XML.

This seems like non-conformant behavior because the XSLT
spec [0] specifies that an XML Process must output the
result tree as a "well-formed XML external general parsed
entity." A well-formed external general parsed entity
(EGPE) may contain multiple top-level elements and is not
subject to the single root-element restriction. The formal
definition of an EPGE is found in the XML Specification
[1].

Is there a workaround for this behavior as this means that
a transform cannot output an XML fragment. Creating a root
element involves adding unnessary complexity and
performance costs to my application.

John Meyer
Senior Software Engineer
Clinician Support Technology
1 Wells Avenue, Suite 201
Newton, MA 02459
www.cstlink.com
[0]
http://www.w3.org/TR/xslt#section-XML-Output-Method

[1]
http://www.w3.org/TR/REC-xml#NT-extParsedEnt
Nov 11 '05 #1
2 3599
John Meyer wrote:
I have an application where I create an xml fragment using
an XslTransform object. However, if I use the following
output method,

<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="no" omit-xml-declaration="yes" standalone="no" />

some of my transforms fail with the following exception:

System.Xml.Xsl.XsltException: There are multiple root
elements in the output XML.


How do you run the transformation? Chances are you are transforming to
XmlWriter, which supports writing of well-formed XML documents only.
Transformation to a Stream works just fine for me.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
John,
I was unable to duplicate this problem.
Here is the code I tried.

System.IO.StringWriter writer = new System.IO.StringWriter();
System.Xml.Xsl.XslTransform xfrm = new System.Xml.Xsl.XslTransform();
XmlDocument xml = new XmlDocument();
xml.LoadXml( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<WorkOrder><ProductID/><OrderDate/><ProductGroup><SerialNo/><SerialNo/><Seri
alNo/></ProductGroup></WorkOrder>");
XmlDocument xsl = new XmlDocument();
xsl.LoadXml( @"<?xml version=""1.0"" encoding=""utf-8"" ?><xsl:stylesheet
xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""
version=""1.0""><xsl:output method=""xml"" version=""1.0""
encoding=""UTF-8"" indent=""no"" omit-xml-declaration=""yes""
standalone=""no"" /> <xsl:template match=""/""> <xsl:copy-of
select=""//SerialNo"" /> </xsl:template></xsl:stylesheet>" );
xfrm.Load( xsl.CreateNavigator());
xfrm.Transform(xml.CreateNavigator(),null,writer);
XmlDocumentFragment frag = xml.CreateDocumentFragment();
frag.InnerXml = writer.ToString();

"John Meyer" <jm****@cstlink.com> wrote in message
news:03****************************@phx.gbl...
I have an application where I create an xml fragment using
an XslTransform object. However, if I use the following
output method,

<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="no" omit-xml-declaration="yes" standalone="no" />

some of my transforms fail with the following exception:

System.Xml.Xsl.XsltException: There are multiple root
elements in the output XML.

This seems like non-conformant behavior because the XSLT
spec [0] specifies that an XML Process must output the
result tree as a "well-formed XML external general parsed
entity." A well-formed external general parsed entity
(EGPE) may contain multiple top-level elements and is not
subject to the single root-element restriction. The formal
definition of an EPGE is found in the XML Specification
[1].

Is there a workaround for this behavior as this means that
a transform cannot output an XML fragment. Creating a root
element involves adding unnessary complexity and
performance costs to my application.

John Meyer
Senior Software Engineer
Clinician Support Technology
1 Wells Avenue, Suite 201
Newton, MA 02459
www.cstlink.com
[0]
http://www.w3.org/TR/xslt#section-XML-Output-Method

[1]
http://www.w3.org/TR/REC-xml#NT-extParsedEnt

Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rodger McNab | last post by:
While parsing xpath expressions within an XSLT document the .NET XslTransform class seems to delete the first "/" after a "]" within an expression containing a "|". This problem can be demonstrated...
1
by: Tim Menninger | last post by:
When I use the XslTransform.Transform method to write to the HttpRequest.OutputStream The first byte of the output is always an invalid character, looks like an ascii zero or some other...
5
by: John Sever | last post by:
My transform in cludes a variable that holds a node set from the node-set() extension function. It the transformation works fine when using MSXML2 or msxsl.exe but not in VB.Net. My code looks...
1
by: Ronald | last post by:
I just wrote some code on a dev machine, Imports System.Xml Imports System.Xml.XPath Imports System.Xml.Xsl Imports System.IO Imports System.Data.SqlClient Public Class ClassXMLtoHTML Dim...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
3
by: Paul Hatcher | last post by:
Hi I have a transform going from XML to HTML, but I can't seem to get the XslTransform class to output &amp; as & even when using disable-output-escaping. I've tried writing the result to a...
1
by: Yuriy | last post by:
Hi, Can anybody explain the following? Say I have the following source XML and XSLT (see below). No matter what this XSLT does. It is just a sample to show a problem. the idea is that XSLT...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
1
by: rmgalante | last post by:
Hello, I have a VB.Net component that uses the XslTransform object. I am using the FXSL randomizeList function in my XSL template. When I transform the XML in the VB.Net component, my...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.