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!

XML, XSLT and JavaScript, can they work together?

Status
Not open for further replies.

drkside2

Technical User
Jul 8, 2004
21
SE
Hi, I have a question, and I had some time thinking of whre to post it, cause it is a mix of XML, XSLT and Javascript... but I decided in the end to post it here in hopes of finding the answer...

I made a file in XML, then made an XSLT for it..the structur of the XMl is based on a story form...like this

<stories>
<story1>
<chapter1>
<chaptername></chaptername>
<para></para>
<para></para>
...
...
</chapter1>
<chapter2>
<chaptername></chaptername>
<para></para>
<para></para>
...
...
</chapter2>
</story1>
<story2>
...
...
</story2>
...
...
</stories>

The XSLT job is primarirly to brake a line every <para></para>, show the Chaptersname and have 3 "bottons" in the end of every chapter. The buttons are as a navigation tool, so that it will load chapter2, 3 and so on... and it loads only one story, I make a new XSLT for every story...

I load it to an HTML file using Javascript, and a code to combine the XML file with the XSLT file for the story I want. but the problem is the following :

The 3 "buttons" are acutally links, and the are intended to be, To Top, Next story and Prev Story. So the thing that I don't know what to do is, when I have that the XSLT file loads all the chapters for a story, I want that Javacsript only shows one of them, and make so the Next and Prev link I made to show the next or prev chapter of where the user is...what code should I use and how?

thnx, if there was anything hard to understand or I misspelled as usuall ;) just ask :)

thnx :)

DrkSide
 
Short answer is "yes". The XSLT can output HTML and JavaScript, and the JavaScript can then interact with the HTML.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
hi
how can XSLT uotput an HTML file? cause the method I use is that in side an HTML file, it is the JavaScript code that combines XML with its XSLT, to show it, the question, I want to controll by JavaScript what it will show from the XSLT, like I tell it show only chapter1 of story1 from the XML file with the XSLT result. And then with Next Chapter and Prev Chapter button....how?

thnx :)
DrkSide
 
I'm not sure, someone else might chime in. But I don't use your methodology.

What I do is write an XSLT that transforms XML to HTML. I write a separate JavaScript for any client-side scripting/navigation/dHTML stuff I need, and put that in a separate .js file.

Then, I include the XSLT in the XML with a standard stylesheet include:

Code:
<?xml-stylesheet type="text/xsl" href="myStyleSheet.xslt"?>

Part of the HTML that is output by the XSLT will include a reference to the appropriate JavaScript in an HTML script block.

Code:
<xsl:template match="/DOCUMENT">
<HTML>
<head>
<script language="JavaScript" src="myScript.js" />
</head>
</xsl:template>

These are just code snippets, but they illustrate the idea. All the user has to do is navigate to the XML file itself. The browser processes the referenced XSLT, which produces the HTML. The HTML references/includes the JavaScript for client-side functionality.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top