Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with " ' ' "

Status
Not open for further replies.

drkside2

Technical User
Jul 8, 2004
21
SE
Hi

I am working on a page that shows my story, stored in an XML page, and I have put a JavaScript code in the XSLT that shows only the selected chapter of my story from the XML page. But I get an error and it is somewhere about the " " thing...

here is how the code should be...
<xsl:for-each select="stories/darkside/ep[@number='1']">
...

and here is the JavaScript code to produce that code:
<script>var chapter=1</script>

<script>
document.write("<xsl:for-each select='stories/darkside/ep[@number='"+chapter+"']'>")
...
</script>

I get an error in this place:

[@number='"+chapter+"']
----------^

can you help me pin point the problem, what have I done wrong?

Thnx for your help :)
want more info about the problem just ask and I will do anything you want :)

THNX !!!
 

Is this code you're running server-side? I ask because this:

Code:
<html>
<head>
	<script>var chapter=1</script>
	<script>
		document.write("<xsl:for-each select='stories/darkside/ep[@number='"+chapter+"']'>")
	</script>
</head>
<body>
</body>
</html>

doesn't error at all for me.

Dan
 
If you have to have quotes around whatever value chapter brings, then try using escape characters:

Code:
\'"+chapter+"\'

...since your select='...' is already bound by single quotes. If that doesn't work, try the escape characters with double-quotes: \""+chapter+"\".

'hope that helps.

--Dave
 
Hi thnx for your answers..

First it is an HTML page that loads the XML file and mix it with an XSLT file using a Javascript...

Then inside the XSLT file, there is a javascript that only show one chapter (called ep inside the XML file) at a time... the problem is when I want to do so I must use a document.write code that also need "", which makes things diffucult cause I also needs to use an attribute seeker to decide which chapter to show. Not to talk much..I have uploaded the files so that you can see the whole thing, and I have updated it with the escape \" code, but still dind't work, can you spare me 5 min and check it out...I would be very gratefull THANK YOU VERY MUCH !! :)

myFiles
 
Even if you escape your quotes correctly, the xml tag will still be incorrect because you'll have single quotes inside of single quotes. Try changing the outer single quotes to escaped double quotes:
Code:
document.write("<xsl:for-each select=[b]\"[/b]stories/darkside/ep[@number='"+chapter+"'][b]\"[/b]>")

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
hi, thnx for your fast answer.....but still I get problem, it compalins about the first escape....

document.write("<xsl:for-each select=\"stories/darkside/ep
-------------------------------------^
[@number='"+chapter+"']\">")

Says something about a string was axpected, but couldn't find a begining qoute charecter...

Can the error be that JavaScript won't work correctly under XSLT or should it work without problems? Thnx :)

cya all tomorrow, GOODNIGHT :)
 
As crazy as this may sound, sometimes the escape character needs an escape character!

Try this:

Code:
document.write("<xsl:for-each select=[b]\\[/b]"stories/darkside/ep[@number='"+chapter+"'][b]\\[/b]">");

Good luck!

--Dave
 
Hi again...thnx all for your help, but I don't understand the JavaScript code works fine, I think the problem is with XSLT, why should it care about what I write inside the JavaScript area??? I even changed the code to following and still I encounter problems...

document.write("<xsl:for-each select="
+
"'stories/darkside/ep[@number='"
+
chapter
+
"']'>");

shouldn't this work properly, cause I won't be needing to any scape charecter anymore, but still I get an error says something about: A necessary whitespace was missing...

what could the problem be, and did the files work correctly in your compeuters with the solutions you gave me? Thnx alot :)


 
Hi, I tired again with a new method...to keep the JS code in an extrenal file, I tested first the XSLT code without the JS code, and it worked, then when I putted the code in an external file, it didn't work, why?
Maybe document.write(""), isn't a good idea, is there another command? thnx
 
Okej, I gave up on it....thnx all for your help, it seams that it won't work...I tried an easier way...to show all the chapters in one page....put a JavaScript code like this:
<script>
ch=1
</script>
<script>
document.write("<a name='"+ch+"'/>")
ch++
</script>

then second code is inside the XSL:for-each command. But still it don't work, I don't get any error message, everything show okej in the page, but the the link doesn't work....when I take the JS code to an HTML site, it works without problems...and if I change the document.write to ("test"+ch), I get test1, test2, test3 without any problems...so what is the mistake I have done in this one?? thnx and I know I have asked to many times, but I don't know who to ask if not you guys, thnx in advance :)

 
The link needs an href or an onclick event to do anything. A name attribute, alone, is not enough.

--Dave
 
hi, I have made the links,

<a href="#1">Ch1</a>

but it didn't work...

thnx anyway for your help :D
bye
 
<script>
chapter="ASD"
document.write("<xsl:for-each select='stories/darkside/ep[@number='"+chapter+"']'>")
</script>

worked for me....

Known is handfull, Unknown is worldfull
 
Hi, thnx for your replay :)

I typed the code you have written, but I get this error:

Required white space was missing. Error processing resource 'file:///C:/Windows/Desktop/New Folder/xml/xsl.xsl'. Line 8, Position 70

Why, is there a problem, with my comp, I tried on my both computers, winXP, and win98....but none did work....can you show more about the xsl code that worked for you?

mine is:
---CODE------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="<xsl:template match="/">
<h2>FALL Studios News</h2>
<script>
chapter="ASD"
document.write("<xsl:for-each select='stories/darkside/ep[@number='"+chapter+"']'>")
</script>
</xsl:template>
</xsl:stylesheet>
--------------------------

THNX!!!
 
oh no, i wasnt referring to the XSL code, i was referring to ur javascript code...

Known is handfull, Unknown is worldfull
 
hi, yepp I know the javascript code, works fine inside an HTML file, but not inside an XSLT file... and that is my problem :(

thnx! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top