View Full Version : How to have only 1 XML linking to multiple XSL
How can i or what element should i use if i want to have just 1 XML linking to multiple XSL .
Eg. Subject: Inside Unit1 got sub-unit (1.1, 1.2, 1.3.....) & i need to put all the text in one XML but can call for different sub-unit at any time.:confused:
dhtroy
10-09-2002, 05:23 AM
You'll need to do your transformation through Java or VB Script in order to do this; although admittedly I've not applied multiple transformations to a single XML file.
Regardless, I've attached a Java Script that I use to handle the XSLT of XML Data Islands. You should be able to use this script to load a single XML Data file into memory, and then assign the processor various XSL files for Transformation.
You might have to tweak the code a bit, but I'm sure you'll get the idea; if not, let me know.
D.
/**********************************************************
Example Multiple XSL Transformations on a single XML
This concept makes use of XML Data Islands that are
transformed through the script and inserted into the
document through the DOM.
*********************************************************/
function loadSource(sourceObj)
{
var xmlDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
xmlDoc.async=false;
xmlDoc.load(sourceObj.XMLDocument);
return xmlDoc;
}
function getProcessor(transformObj)
{
if (table_proc==null) {
var xslDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate");
xslDoc.async=false;
xslDoc.load(transformObj.XMLDocument);
xslTemplate.stylesheet=xslDoc;
xslProcessor=xslTemplate.createProcessor();
table_proc=xslProcessor;
}
else {
xslProcessor=table_proc;
}
return xslProcessor;
}
function transformData(srcDoc,processor)
{
var resultDoc=new ActiveXObject("MSXML2.DOMDocument");
processor.input=srcDoc;
processor.output=resultDoc;
processor.transform();
return resultDoc;
}
function loadXMLData()
{
// loads your XML data file here
var srcDoc=loadSource(xmlData);
// assigns an XSL document to the XML Parser
var processor=getProcessor(xslFile);
// does the XSLT
var rsltDoc=transformData(srcDoc,processor);
// insert the transformed data into the document
xmlArea.innerHTML=rsltDoc.xml;
// if you had more than ONE XLST to do ... set-up another parser
processor=getProcessor(another_xslFile);
rsltDoc=transformData(srcDoc,processor);
xmlArea2.innerHTML=rsltDoc.xml;
// etc....
}
////////////////////////////////////////////////////////////////////////////
// main
//
// Description of script variables
// xmlData = XML Data Island in your HTML Document <xml id="xmlData" src="mydata.xml"></xml>
// xslFile = link to your XSL file <xml id="xslFile" src="mytransform.xsl"></xml>
// xmlArea = div tag where transformed data is inserted <div id="xmlArea"></div>
//
//
////////////////////////////////////////////////////////////////////////////
var table_proc = null;
loadXMLData();
Thanks dhtroy for your info but sad thing is that i don't know VBscript. Is there other way to do it. Check with u, can we use the Xpath cos i read it at www.w3schools.com but still blurred.
Alex Vincent
10-11-2002, 02:56 AM
Why can't you have multiple <?xml-stylesheet ?> processing instructions?
Because im a project student (My task was to convert the current HTML courseware to XML) & my lecturer wants all the data to be in one XML. He say that if i have one XML & one XSL, what's the difference having the HTML.You know, Sometimes, u just got to listen.....
dhtroy
10-12-2002, 06:53 PM
Well, I read your most recent posting, and have to say I'm a tad bit confused as to what you're trying to do and why you'd need multiple XSL files to do it (e.g., converting a single HTML document to use XML and XSL ).
Additionally, I read what Alex had posted re: using multiple style-sheets to transform the XML, and that might be more in line with what you're trying to do. The Java Script I provided allows for the following (just so you know) : one, in order to use the latest version of the MSXML parser, you must instanciate it through an ActiveX Object in Script. Using embedded XML-Style sheet tags in your XML file do not allow for this, and (2) you can direct the transformed XML to a particular location in your HTML document, for more control.
So explain why you're needing to use Multiple XSL files and what it is you're trying to accomplish and we'll see what we can come up with ... :thumbsup:
Thanks dtroy & everyone for your guidance but i think just forget abt the whole thing lah cos my time is running out. Thanks
jonnyv
03-26-2009, 06:50 PM
I want help on this!!! I am currently writing my first real xml file. It's for a church website, and there's a section on the page where it has this weeks events. I wrote it in xml because I thought this would make it easy for anyone with or without website knowledge to update their site.
So I have the events set up, and the xml file working fine, and when I look at the full page in the browser, it works how I want it to. However, what I'm wanting to do (I dont know if this is possible) is to have a link on the event title to open up a pop-up window with the information for that event.
So to show my example, the file is called this_week.xml, and is set up like this:
<event>
<Day>Sunday</Day>
<Date>01</Date>
<Month>03</Month>
<Year>2009</Year>
<Title>First of Month</Title>
<Comment>Today is the first day of the month. This means PINCH PUNCH FIRST OF THE MONTH! NO RETURNS!</Comment>
<Link>event.xsl</Link>
</event>
(I know the link section isnt right!)
On the full page view, it ends up looking like this:
Sunday, 01 First of Month
But I was wondering whether I could link the <Title> to open up a pop-up so it uses all the information here so it looks like this:
First of Month
01/03/2009
Today is the first day of the month. This means PINCH PUNCH FIRST OF THE MONTH! NO RETURNS!
Sorry if this is confusing
Jonny
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.