473,385 Members | 1,838 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,385 software developers and data experts.

What's wrong with xsl's copy-of?

11
"'copyof.xsl"
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.   <xsl:template match="/">
  5.     <html>
  6.       <head>
  7.         <SCRIPT LANGUAGE="JavaScript">
  8.           <xsl:comment>
  9.             <![CDATA[
  10. function window.onload()
  11. {
  12.    alert(xmlData.xml);
  13. }
  14.             ]]>
  15.           </xsl:comment>
  16.         </SCRIPT>
  17.       </head>
  18.       <xml id="xmlData">
  19.         <xsl:copy-of select="*"/>
  20.       </xml>
  21.     </html>
  22.   </xsl:template>
  23. </xsl:stylesheet>
  24.  
"good.xml"
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type='text/xsl' href='copyof.xsl'?>
  3. <Apple name="Farm">
  4.   <Tag name="West"/>
  5. </Apple>
"bad.xml"
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type='text/xsl' href='copyof.xsl'?>
  3. <Apple name="Farm">
  4.   <Tag name="West&amp;lt;"/>
  5. </Apple>
Notice that the only difference of 2 xml files is
<Tag name="West&lt;"/>
bad.xml has a special characters "&lt;", good.xml can get expected result in IE, but bad.xml couldn't...

Anyone can help me to figure out what's wrong and how to resolve the bad.xml file?
Nov 27 '07 #1
16 2158
jkmyoung
2,057 Expert 2GB
It's probably the entity &lt; which is <

Does it work if you double-escape it?
<Tag name="West&amp;lt;"/>
Nov 27 '07 #2
sinbao
11
It's probably the entity &lt; which is <

Does it work if you double-escape it?
<Tag name="West&amp;lt;"/>
Yes, it works, but what i wanted here is a < not &lt;
Nov 28 '07 #3
jkmyoung
2,057 Expert 2GB
Don't think it's doable then. The < would break the well-formedness of the xml.
Nov 29 '07 #4
sinbao
11
Nobody ever encountered this problem?
Dec 4 '07 #5
jkmyoung
2,057 Expert 2GB
People have encountered this problem, but it is part of IE's expected behaviour. It doesn't display malformed code correctly.

What you're doing is not allowed.

If you want to force it to work, then you would need to write your own web browser.
Dec 4 '07 #6
sinbao
11
but why can't only "copy-of" work?

the following xsl can work:
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2.   <xsl:template match="/">
  3.     <html>
  4.         <body>
  5.       <xsl:apply-templates select="Apple/Tag"/>
  6.         </body>
  7.     </html>
  8.   </xsl:template>
  9.   <xsl:template match="Tag">
  10.     <xsl:value-of select="@name"/>
  11.   </xsl:template>
  12. </xsl:stylesheet>
  13.  
Dec 10 '07 #7
jkmyoung
2,057 Expert 2GB
Looking at it from another point of view,
Your problem is that you're using xmlData.xml.
When you load invalid xml, the call to the xml property returns the empty string because it is invalid xml.

What you want is a text string instead of xml.
Dec 10 '07 #8
sinbao
11
jkmyoung, thanks very much, but I have some disagreement.
1. I don't think it will work if I try to get the text string of xmlData.
2. It is not a invalid xml, since it will display well using the above style.
Dec 18 '07 #9
jkmyoung
2,057 Expert 2GB
1. No, because it is invalid XML and thus doesn't load properly. I suggested using a string object instead of an xml object.
2. What do you mean above style? Do you mean the proper xml works?
Dec 19 '07 #10
sinbao
11
1. No, because it is invalid XML and thus doesn't load properly. I suggested using a string object instead of an xml object.
2. What do you mean above style? Do you mean the proper xml works?
I mean bad.xsl works well using this style sheet:
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2.   <xsl:template match="/">
  3.     <html>
  4.         <body>
  5.       <xsl:apply-templates select="Apple/Tag"/>
  6.         </body>
  7.     </html>
  8.   </xsl:template>
  9.   <xsl:template match="Tag">
  10.     <xsl:value-of select="@name"/>
  11.   </xsl:template>
  12. </xsl:stylesheet>
So that means it is not an invalid xml file, only "copy-of" can't work...
Dec 21 '07 #11
Try this, I am using decimal entity for less than in xml file and the tag "<xsl:output method="xml" indent="yes" version="1.0" encoding="ISO-8859-1"/>" in xsl, it shows &lt;, but the proper symbol not viewing


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type='text/xsl' href='copyof.xsl'?>
  3.  
  4. <Apple name="Farm">
  5.   <Tag name="West<"/>
  6. </Apple>
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
  3. <xsl:output method="xml" indent="yes" version="1.0" encoding="ISO-8859-1"/>
  4.   <xsl:template match="/">
  5.     <html>
  6.       <head>
  7.         <SCRIPT LANGUAGE="JavaScript">
  8.           <xsl:comment>
  9.             <![CDATA[
  10. function window.onload()
  11. {
  12.    alert(xmlData.xml);
  13. }
  14.             ]]>
  15.           </xsl:comment>
  16.         </SCRIPT>
  17.       </head>
  18.       <xml id="xmlData">
  19.         <xsl:copy-of select="*"/>
  20.       </xml>
  21.     </html>
  22.   </xsl:template>
  23. </xsl:stylesheet>
Dec 21 '07 #12
That is "West(ampersand ash 60 semicolon)"
Dec 21 '07 #13
Without opening and closing braces. Is it working in your system?
Dec 21 '07 #14
jkmyoung
2,057 Expert 2GB
what browser are you using? value-of does not work for me.
Dec 22 '07 #15
sinbao
11
Try this, I am using decimal entity for less than in xml file and the tag "<xsl:output method="xml" indent="yes" version="1.0" encoding="ISO-8859-1"/>" in xsl, it shows &lt;, but the proper symbol not viewing
yeah, the line
Expand|Select|Wrap|Line Numbers
  1. <xsl:output method="xml" indent="yes" version="1.0" encoding="ISO-8859-1"/>
really works, although I just remove the "encoding" attribute :-)
amazing, what does it do?
Dec 24 '07 #16
yeah, the line
Expand|Select|Wrap|Line Numbers
  1. <xsl:output method="xml" indent="yes" version="1.0" encoding="ISO-8859-1"/>
really works, although I just remove the "encoding" attribute :-)
amazing, what does it do?

Sorry, I also dont know exactly, but long back I also faced the viewing problem, while on that time, I had been searched and used it.
Dec 26 '07 #17

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

Similar topics

5
by: Thomas Vackier | last post by:
Hi all, I'm trying to delete a certain tag in an XML document using XSL, but I can't figure out how. Here's how my XML looks like: <root> <element> <name>This is text</name>
6
by: insane79 | last post by:
Hi, i have one problem with an xsl trasformation (I'm using Xalan) The source XML document is the following: <?xml version = '1.0' encoding = 'ISO-8859-1'?> <ROOT...
3
by: Tjerk Wolterink | last post by:
Hello, i've an xml doc like this: <doc> <item>a</item> <item>b</item> <item>c</item> <item>d</item> <item>e</item> <item>f</item> <item>g</item>
11
by: Tjerk Wolterink | last post by:
I've a problem in an xsl transformation. My xml input: --- input.xml --- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE xc:content > <xc:xcontent...
4
by: Chris | last post by:
I have the following XML: <?xml version="1.0" encoding="ISO-8859-1" ?> <ORDERS> <ORDER> <ORDER_ID>123</ORDER_ID> <X>a</X> <X>e</X> <X>f</X> </ORDER>
2
by: Beniamin Tecar | last post by:
Hi, I have an xml : <DataRecords> <Point Alias='A' Value='1' Status='0' /> <Point Alias='B' Value='2' Status='0' /> </DataRecords> I have needed by an XSL to insert a node between...
3
by: bhushan.kharabe | last post by:
Hi, I am stuck in problem involving transformation where the tree structure of the target is different than the tree structure of the source. My input xml looks like <?xml version="1.0"...
3
by: @do | last post by:
Hi! My XML File is something like this: <?xml version="1.0" encoding="ISO-8859-1"?> <item_list> <item_list_elements> <code>01600</code> <name>John</name> <text>some text ABC</text>
5
by: Simon Brooke | last post by:
This is supposed to be a very simple XSL stylesheet to strip styling information out of HTML documents - it could not be more basic. And yet, it doesn't work. I'm obviously getting something very...
2
by: mtugnoli | last post by:
I've found a sample on http://msdn2.microsoft.com/en-us/library/ms766561.aspx to filter a .XML ex. <?xml version="1.0"?> <COLLECTION dateCreated="01-04-2000"> <BOOK> <TITLE>Splish...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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,...

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.