I am using C# to transform an XML document which actually outputs another XML document using XslCompiledTran sform and an XmlTextWriter.
The code I am using is: -
XslCompiledTransform myXslTrans = new XslCompiledTransform();
-
myXslTrans.Load("sortByExtension.xsl");
-
XmlTextWriter myWriter = new XmlTextWriter("result.xml", null);
-
myXslTrans.Transform(tvXML, null, myWriter);
-
myWriter.Close();
-
The problem is, when I open the new XML document, "result.xml " I recieve an error because in my XSL I use the following to declare a node.
<root name="PlanRepos itory">
</root>
and the output in the XML file still has the <l and > instead of the < and >.
Is there any setting I can change in the XmlTextWriter or any way to change this within the actual XSL Document?
Hope to find an answer soon, thanks!
8 22974 jkmyoung 2,057
Recognized Expert Top Contributor
Is there any reason you can't use < and > in your xsl?
It gives me an error because its expects the "<" to start an xsl or html element, much like using a " in some languages expects a string to be started. In other languages, there is usually an escape character, such as a /or \, but I can't seem to find anything that works in XSL.
jkmyoung 2,057
Recognized Expert Top Contributor
Aren't you declaring a node here? - &lt;root name="PlanRepository"&gt;
-
&lt;/root&gt;
Might help if we could see the rest of your xslt.
This is my XSL: -
<xsl:template match="root">
-
&lt;root name="PlanRepository"&gt;
-
<xsl:apply-templates />
-
&lt;/root&gt;
-
</xsl:template>
-
-
<xsl:template match="directory">
-
&lt;directory name="<xsl:value-of select="@name"/>"&gt;
-
<xsl:choose>
-
<xsl:when test="@name = 'SAFE_Output'">
-
<xsl:for-each select="file">
-
<xsl:sort select="substring-after(substring-after(.,'.'),'.')" />
-
&lt;file&gt;<xsl:value-of select="."/>&lt;/file&gt;
-
</xsl:for-each>
-
</xsl:when>
-
<xsl:otherwise>
-
<xsl:for-each select="file">
-
<xsl:sort select="substring-after(.,'.')" />
-
&lt;file&gt;<xsl:value-of select="."/>&lt;/file&gt;
-
</xsl:for-each>
-
</xsl:otherwise>
-
</xsl:choose>
-
<xsl:apply-templates select="directory"/>
-
&lt;/directory&gt;
-
</xsl:template>
When I apply this to an HTML file using an XmlTextWriter the < and > show up. But when I apply it to an XML file using an XmlTextWriter, the < and > show up, causing it to be an invalid XML file.
jkmyoung 2,057
Recognized Expert Top Contributor
Does using this not work in both cases? - <xsl:template match="root">
-
<root name="PlanRepository">
-
<xsl:apply-templates/>
-
</root>
-
</xsl:template>
-
<xsl:template match="directory">
-
<directory>
-
<xsl:copy-of select="@name"/>
-
<xsl:choose>
-
<xsl:when test="@name = 'SAFE_Output'">
-
<xsl:for-each select="file">
-
<xsl:sort select="substring-after(substring-after(.,'.'),'.')"/>
-
<xsl:copy-of select="."/>
-
</xsl:for-each>
-
</xsl:when>
-
<xsl:otherwise>
-
<xsl:for-each select="file">
-
<xsl:sort select="substring-after(.,'.')"/>
-
<xsl:copy-of select="."/>
-
</xsl:for-each>
-
</xsl:otherwise>
-
</xsl:choose>
-
<xsl:apply-templates select="directory"/>
-
</directory>
-
</xsl:template>
Yes, in both cases, replacing the < and > with < and > causes errors.
This is the error I get: -
-
System.Xml.Xsl.XslLoadException: XSLT compile error. ---> System.Xml.XmlException: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 11, position 22.
-
-
jkmyoung 2,057
Recognized Expert Top Contributor
The validator is unfortunately incorrect then. Try using this, it uses <xsl:copy> instead. - <xsl:template match="root">
-
<xsl:copy>
-
<xsl:attribute name="name">PlanRepository</xsl:attribute>
-
<xsl:apply-templates/>
-
</xsl:copy>
-
</xsl:template>
-
<xsl:template match="directory">
-
<xsl:copy>
-
<xsl:copy-of select="@name"/>
-
<xsl:choose>
-
<xsl:when test="@name = 'SAFE_Output'">
-
<xsl:for-each select="file">
-
<xsl:sort select="substring-after(substring-after(.,'.'),'.')"/>
-
<xsl:copy-of select="."/>
-
</xsl:for-each>
-
</xsl:when>
-
<xsl:otherwise>
-
<xsl:for-each select="file">
-
<xsl:sort select="substring-after(.,'.')"/>
-
<xsl:copy-of select="."/>
-
</xsl:for-each>
-
</xsl:otherwise>
-
</xsl:choose>
-
<xsl:apply-templates select="directory"/>
-
</xsl:copy>
-
</xsl:template>
? "invalid attribute character." ?
I didn't see the attribute.
That worked! Thanks so much for going through this process with me and helping me figure it out. I really appreciate it.
Andrew
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Harald Servat Gelabert |
last post by:
Dear news-team
I'm using MySQL 4.0.15a (with PHP 4.3.4rc1 and Apache 2.0.47 under FreeBSD).
I'm having problems when updating a column of a table (it updates an extra
column).
As an example, I provide this sample (data_registre, data_ultima_connexio are
the outputs of the SELECT).
|
by: Gazchurchend |
last post by:
I am trying to connect to a legacy system running on VMS using the
Attunity Connect ODBC driver from within PHP. I know the System DSN
works because SQL Server has been using it successfully for years. I
want to access the info on VMS from within PHP and this is when all
goes pear shaped!
I have tried various ways...
1) If I am in query analyser and type 'SELECT * FROM
DNSNAME...TABLENAME' etc. This works fine. But if I try putting...
|
by: Tjerk Wolterink |
last post by:
In XHTML the entity nbsp stands for
A normal space like " " is also displayed as an normal space,
but multiple spaces like " " are interpreted as 1 space in the
xhtml page.
So there comes the in handy: with " " you have two
spaces. So with the nbsp entity you can create multiple spaces (in the display).
Now i have an xml file with entities,
i put it in an xsl-file that know xhtml entities.
|
by: Paminu |
last post by:
In math this expression:
(a < b) && (b < c)
would be described as:
a < b < c
But why is it that in C these two expressions evaluate to something
different for the same values of a, b and c?
|
by: Rock |
last post by:
I'm in the process of writing this program for complex numbers and I
use DevC++. My professor on the other hand compiles on Borland 5.5. So
I ocasionally save and run my work on Borland to see if it caught
anything, it's very picky... Anyway, the code below works on Dev, and
it compiles fine on Borland, but when I run it from borland, there is
no output, no error, it just skips right over the freind ostream call.
HELP! I'm new to this...
| |
by: toton |
last post by:
Hi,
I have little confusion about static memory allocation & dynamic
allocation for a cluss member.
I have class like
class Bar{
public:
explicit Bar(){
cout<<"bar default"<<endl;
}
|
by: Sin Jeong-hun |
last post by:
I created a windows form application. It has a Threading.Timer and when
the timer ticks it does some work and show a popup window.
The problem is that while this program is running if the user tries to
shutdown Windows, my application doesn't quit and neither does
Windows. Of course, if the user first click of my application and
then tries to shutdown, there is no problem.
To solve this problem, I overrode WndProc of the main form,...
|
by: =?Utf-8?B?U2hvb3Rlcg==?= |
last post by:
Hi,
We have an MCMS Site displaying content in ten different languages.
The problem is that when any other language is being used bar english the
title which is set to a placeholder is displaying strange square characters.
Has anyone come across this problem before and come up with a fix?
|
by: biganthony via AccessMonster.com |
last post by:
Hi,
I decided to install Office 2003 Service Pack 3 on my home computer to test
(in full knowledge that there may be some issues with it). After installation,
I have noticed that with a small database I wrote for home, the combo boxes
and listboxes no longer display the bound column. For example, on a form I
have a combo box based on a table called 'names'. The two columns in the
combo box are ID and Surname. The combo box and list box...
|
by: monirul arfin |
last post by:
Hi all,
when I'm using yahoo mssenger it is automatically sign out & after few second it is automatically sign in. I thought that it could be messnger problem, so I reinstall it, but same problem. Some of my freinds has same problem.
Is it server or net connection problem ? But web yahoo messenger is alright.
And net speed also alright (10.0 Mbps).
And one more question, "Microsoft Visual C++ 2005 Redistributable" this program i found in...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |