473,729 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL to XML &lt; to < problem

11 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. XslCompiledTransform myXslTrans = new XslCompiledTransform();
  2. myXslTrans.Load("sortByExtension.xsl");
  3. XmlTextWriter myWriter = new XmlTextWriter("result.xml", null);
  4. myXslTrans.Transform(tvXML, null, myWriter);
  5. myWriter.Close();
  6.  
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.

&lt;root name="PlanRepos itory"&gt;
&lt;/root&gt;

and the output in the XML file still has the &ltl and &gt; 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!
Jul 18 '07 #1
8 22974
jkmyoung
2,057 Recognized Expert Top Contributor
Is there any reason you can't use < and > in your xsl?
Jul 18 '07 #2
ajc308
11 New Member
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.
Jul 18 '07 #3
jkmyoung
2,057 Recognized Expert Top Contributor
Aren't you declaring a node here?
Expand|Select|Wrap|Line Numbers
  1. &amp;lt;root name="PlanRepository"&amp;gt;
  2. &amp;lt;/root&amp;gt;
Might help if we could see the rest of your xslt.
Jul 18 '07 #4
ajc308
11 New Member
This is my XSL:

Expand|Select|Wrap|Line Numbers
  1.  <xsl:template match="root">
  2.   &amp;lt;root name="PlanRepository"&amp;gt;
  3.   <xsl:apply-templates />
  4.   &amp;lt;/root&amp;gt;
  5. </xsl:template>
  6.  
  7. <xsl:template match="directory">
  8.   &amp;lt;directory name="<xsl:value-of select="@name"/>"&amp;gt;
  9.   <xsl:choose>
  10.     <xsl:when test="@name = 'SAFE_Output'">
  11.       <xsl:for-each select="file">
  12.         <xsl:sort select="substring-after(substring-after(.,'.'),'.')" />
  13.         &amp;lt;file&amp;gt;<xsl:value-of select="."/>&amp;lt;/file&amp;gt;
  14.       </xsl:for-each>
  15.     </xsl:when>
  16.     <xsl:otherwise>
  17.       <xsl:for-each select="file">
  18.         <xsl:sort select="substring-after(.,'.')" />
  19.         &amp;lt;file&amp;gt;<xsl:value-of select="."/>&amp;lt;/file&amp;gt;
  20.       </xsl:for-each>
  21.     </xsl:otherwise>
  22.   </xsl:choose>
  23.   <xsl:apply-templates select="directory"/>
  24.   &amp;lt;/directory&amp;gt;
  25. </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 &lt; and &gt; show up, causing it to be an invalid XML file.
Jul 18 '07 #5
jkmyoung
2,057 Recognized Expert Top Contributor
Does using this not work in both cases?

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="root">
  2.     <root name="PlanRepository">
  3.         <xsl:apply-templates/>
  4.     </root>
  5. </xsl:template>
  6. <xsl:template match="directory">
  7.     <directory>
  8.         <xsl:copy-of select="@name"/>
  9.         <xsl:choose>
  10.             <xsl:when test="@name = 'SAFE_Output'">
  11.                 <xsl:for-each select="file">
  12.                     <xsl:sort select="substring-after(substring-after(.,'.'),'.')"/>
  13.                     <xsl:copy-of select="."/>
  14.                 </xsl:for-each>
  15.             </xsl:when>
  16.             <xsl:otherwise>
  17.                 <xsl:for-each select="file">
  18.                     <xsl:sort select="substring-after(.,'.')"/>
  19.                     <xsl:copy-of select="."/>
  20.                 </xsl:for-each>
  21.             </xsl:otherwise>
  22.         </xsl:choose>
  23.         <xsl:apply-templates select="directory"/>
  24.     </directory>
  25. </xsl:template>
Jul 18 '07 #6
ajc308
11 New Member
Yes, in both cases, replacing the &lt; and &gt; with < and > causes errors.

This is the error I get:

Expand|Select|Wrap|Line Numbers
  1.  
  2. System.Xml.Xsl.XslLoadException: XSLT compile error. ---> System.Xml.XmlException: '&lt;', hexadecimal value 0x3C, is an invalid attribute character. Line 11, position 22.
  3.  
  4.  
Jul 18 '07 #7
jkmyoung
2,057 Recognized Expert Top Contributor
The validator is unfortunately incorrect then. Try using this, it uses <xsl:copy> instead.

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="root">    
  2.     <xsl:copy>
  3.         <xsl:attribute name="name">PlanRepository</xsl:attribute>
  4.         <xsl:apply-templates/>
  5.     </xsl:copy>
  6. </xsl:template>
  7. <xsl:template match="directory">
  8.     <xsl:copy>
  9.         <xsl:copy-of select="@name"/>
  10.         <xsl:choose>
  11.             <xsl:when test="@name = 'SAFE_Output'">
  12.                 <xsl:for-each select="file">
  13.                     <xsl:sort select="substring-after(substring-after(.,'.'),'.')"/>
  14.                     <xsl:copy-of select="."/>
  15.                 </xsl:for-each>
  16.             </xsl:when>
  17.             <xsl:otherwise>
  18.                 <xsl:for-each select="file">
  19.                     <xsl:sort select="substring-after(.,'.')"/>
  20.                     <xsl:copy-of select="."/>
  21.                 </xsl:for-each>
  22.             </xsl:otherwise>
  23.         </xsl:choose>
  24.         <xsl:apply-templates select="directory"/>
  25.     </xsl:copy>
  26. </xsl:template>
? "invalid attribute character." ?
I didn't see the attribute.
Jul 19 '07 #8
ajc308
11 New Member
That worked! Thanks so much for going through this process with me and helping me figure it out. I really appreciate it.

Andrew
Jul 19 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7152
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).
2
3541
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...
12
6031
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 &nbsp; in handy: with "&nbsp;&nbsp;" you have two spaces. So with the nbsp entity you can create multiple spaces (in the display). Now i have an xml file with &nbsp; entities, i put it in an xsl-file that know xhtml entities.
72
4211
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?
4
6747
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...
11
3048
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; }
2
2566
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,...
2
1119
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?
2
7047
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...
0
2683
monirul arfin
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...
0
8921
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, 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...
0
8763
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,...
0
9427
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, 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...
1
9202
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,...
0
8151
agi2029
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...
0
4528
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...
1
3238
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
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
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...

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.