473,666 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

applying 2 xslt to an xml via script?

Hi All

I am completely new to this, but I was wondering if I can apply 2 xslt's
subsequently to an xml, via the (client side) scripting method:

http://www.w3schools.com/xsl/xsl_client.asp

Like maybe:

<html>
<body>

<script type="text/javascript">

// Load XML
var xml = new ActiveXObject(" Microsoft.XMLDO M")
xml.async = false
xml.load("cdcat alog.xml")

// Load XSL ---- 1 ----
var xsl = new ActiveXObject(" Microsoft.XMLDO M")
xsl.async = false
xsl.load("cdcat alog.xsl")

// Transform ---- 1 ----
document.write( xml.transformNo de(xsl))

// Load XSL ---- 2 -----
var xsl2 = new ActiveXObject(" Microsoft.XMLDO M")
xsl.async = false
xsl.load("cdcat alog2.xsl")

// Transform ---- 2 -----
document.write( xml.transformNo de(xsl2))

</script>

</body>
</html>

Thaks for letting me know some scripting hints if anyone came across similar
situation.

Toby
Sep 20 '06 #1
8 2073


to*****@hotpop. com wrote:

I am completely new to this, but I was wondering if I can apply 2 xslt's
subsequently to an xml, via the (client side) scripting method:
<html>
<body>

<script type="text/javascript">

// Load XML
var xml = new ActiveXObject(" Microsoft.XMLDO M")
xml.async = false
xml.load("cdcat alog.xml")

// Load XSL ---- 1 ----
var xsl = new ActiveXObject(" Microsoft.XMLDO M")
xsl.async = false
xsl.load("cdcat alog.xsl")

// Transform ---- 1 ----
document.write( xml.transformNo de(xsl))

// Load XSL ---- 2 -----
var xsl2 = new ActiveXObject(" Microsoft.XMLDO M")
xsl.async = false
xsl.load("cdcat alog2.xsl")

// Transform ---- 2 -----
document.write( xml.transformNo de(xsl2))

</script>

</body>
</html>
Well new ActiveXObject(' Microsoft.XMLDO M') works with IE/Win if ActiveX
is enabled. And even with IE whether the object created with new
ActiveXObject(' Microsoft.XMLDO M') supports XSLT 1.0 depends on the IE
version (IE 6 and later will do, IE 5 or IE 5.5 require MSXML 3 to be
installed in replace mode). Other browsers like Mozilla or Opera do not
support script creation of ActiveX objects.

transformNode gives a string, document.write expects a string thus if
you need/want to do two document.write calls with a string result of
transformNode passed in then you can do. Those stylesheets hopefully
generate HTML snippets that belong inside the body of an HTML document.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 20 '06 #2
Martin Honnen wrote:
>

to*****@hotpop. com wrote:

>I am completely new to this, but I was wondering if I can apply 2
xslt's subsequently to an xml, via the (client side) scripting method:


><html>
<body>

<script type="text/javascript">

// Load XML
var xml = new ActiveXObject(" Microsoft.XMLDO M")
xml.async = false
xml.load("cdca talog.xml")

// Load XSL ---- 1 ----
var xsl = new ActiveXObject(" Microsoft.XMLDO M")
xsl.async = false
xsl.load("cdca talog.xsl")

// Transform ---- 1 ----
document.write (xml.transformN ode(xsl))

// Load XSL ---- 2 -----
var xsl2 = new ActiveXObject(" Microsoft.XMLDO M")
xsl.async = false
xsl.load("cdca talog2.xsl")

// Transform ---- 2 -----
document.write (xml.transformN ode(xsl2))

</script>

</body>
</html>


Well new ActiveXObject(' Microsoft.XMLDO M') works with IE/Win if ActiveX
is enabled. And even with IE whether the object created with new
ActiveXObject(' Microsoft.XMLDO M') supports XSLT 1.0 depends on the IE
version (IE 6 and later will do, IE 5 or IE 5.5 require MSXML 3 to be
installed in replace mode). Other browsers like Mozilla or Opera do not
support script creation of ActiveX objects.
Is there a type of scripting, one that does not need activex, that works for
different browsers, at the least ie5 and up and firefox?

>
transformNode gives a string, document.write expects a string thus if
you need/want to do two document.write calls with a string result of
transformNode passed in then you can do. Those stylesheets hopefully
generate HTML snippets that belong inside the body of an HTML document.
The second one produces html from xml, the first one produces XML from a special
form of XML.

I figured out how to merge the 2 xsl into one, but the initial question would
still be interesting how to do it.
>
Sep 20 '06 #3

to*****@hotpop. com wrote:
I am completely new to this, but I was wondering if I can apply 2 xslt's
subsequently to an xml, via the (client side) scripting method:
[Explictly coded client-side JavaScript transforms via MSXML]
Yes, this is dead easy. Use two XSL documents and apply them one after
the other.

Remember to get the _results_ of the first transform as returned by the
..transformNode () method into a variable, rather than writing it back
directly. Then apply the second transform to _this_, not to your
original XML source.

Sep 21 '06 #4
Andy Dingley wrote:
to*****@hotpop. com wrote:

>>I am completely new to this, but I was wondering if I can apply 2 xslt's
subsequentl y to an xml, via the (client side) scripting method:
[Explictly coded client-side JavaScript transforms via MSXML]


Yes, this is dead easy. Use two XSL documents and apply them one after
the other.

Remember to get the _results_ of the first transform as returned by the
.transformNode( ) method into a variable, rather than writing it back
directly. Then apply the second transform to _this_, not to your
original XML source.
OK, I think I will be able to do this. However, from what I know, the script
would work only for MS IE and not for Firefox. Actually I think the entire
approach is useless, if it doesnt work for Firefox.
Sep 21 '06 #5


to*****@hotpop. com wrote:

Is there a type of scripting, one that does not need activex, that works
for different browsers, at the least ie5 and up and firefox?
Firefox has its own API exposed to script to run XSLT transformations ,
it is documented here:
<http://developer.mozil la.org/en/docs/Using_the_Mozil la_JavaScript_i nterface_to_XSL _Transformation s>
Opera 9 also supports that API.

Note that this API integrates well with the W3C DOM API in allowing you
to get a document fragment node as the transformation result and insert
it into a target document. Using document.write with that API is not
really a good idea in my view, as you would first serialize the result
nodes to a string to have document.write feed it to a parser again to
create nodes.

The second one produces html from xml, the first one produces XML from a
special form of XML.
Then you don't want the approach taken in your script example, instead
you want to chain the transformations , with MSXML you would use
transformNodeTo Object to transform the original XML with the first
stylesheet into a second XML document on which you could then do
transformNode to get the HTML result.

With Mozilla/Firefox you would use transformToDocu ment first to
transform XML to XML and then in my view transformToFrag ment to
transform the XML to a HTML document fragment which you could then
insert with e.g. appendChild as needed.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 21 '06 #6

to*****@hotpop. com wrote:
However, from what I know, the script
would work only for MS IE and not for Firefox. Actually I think the entire
approach is useless, if it doesnt work for Firefox.
If you read the right tutorials (recent ones, probably mentioning AJAX)
then some slightly more sophisticated code will work on either.

It's not entirely web-portable, but it's usefully so.

Sep 21 '06 #7
Martin Honnen wrote:
>

to*****@hotpop. com wrote:

>Is there a type of scripting, one that does not need activex, that
works for different browsers, at the least ie5 and up and firefox?


Firefox has its own API exposed to script to run XSLT transformations ,
it is documented here:
<http://developer.mozil la.org/en/docs/Using_the_Mozil la_JavaScript_i nterface_to_XSL _Transformation s>
This page www.w3schools.com/xsl/xsl_client.asp shows the example for IE. Sorry,
I am so new to all this stuff. Do you have a link to a page that shows me how to
code this for Firefox?

Opera 9 also supports that API.

Note that this API integrates well with the W3C DOM API in allowing you
to get a document fragment node as the transformation result and insert
it into a target document. Using document.write with that API is not
really a good idea in my view, as you would first serialize the result
nodes to a string to have document.write feed it to a parser again to
create nodes.

>The second one produces html from xml, the first one produces XML from
a special form of XML.


Then you don't want the approach taken in your script example, instead
you want to chain the transformations , with MSXML you would use
transformNodeTo Object to transform the original XML with the first
stylesheet into a second XML document on which you could then do
transformNode to get the HTML result.
I think I can do this, thanks. I also was able to merge the 2 XSLs into a single
one. Dont know what would be preferable.
With Mozilla/Firefox you would use transformToDocu ment first to
transform XML to XML and then in my view transformToFrag ment to
transform the XML to a HTML document fragment which you could then
insert with e.g. appendChild as needed.

Sep 21 '06 #8
I think I can do this, thanks. I also was able to merge the 2 XSLs into
a single one. Dont know what would be preferable.
A single combined transformation will generally be more efficient than
two in succession.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Sep 21 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2700
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the same XML file with XSL file with a program called XMLspy and i obtained the desire and waited...
2
2380
by: Jon Martin Solaas | last post by:
For java programmers there exist a framework called Millstone (www.millstone.org) for programming web user-interfaces in a component oriented way. Millstone uses xslt transformations to render components as html. I'm trying to modify millstone so that it can display a html editor widget called HTMLArea instead of the usual html <textarea> tag. But I need a little help with the xslt transformation. Especially there is a construct,...
7
4118
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:my-javascript-ext="my-ext1" extension-element-prefixes="my-javascript-ext"
6
4683
by: RC | last post by:
Hello World, I am try do call a JavaScript function from XSLT, but I got function not avaible error. See "????" below. Would someone out there tell me how? Thank Q! <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" /> <xsl:template match="/">
4
5235
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
1
1633
by: John Moore | last post by:
I have a set of code that is called on every page load that loads an xslt file. The xslt file has an embedded <script> tag. Loading the page mutliple times causes aspnet_wp.exe to use all available memory and then reset. As this happens several times over the course of an 8 hour stress run, I'm looking for a solution. The xslt file has the following: <xsl:if test="$strPageCaller=''"> <SCRIPT LANGUAGE="JavaScript">BPB()</SCRIPT>...
3
1756
by: Simon Brooke | last post by:
I've been doing XSL transforms, converting XML to HTML, server side since 2000. In those days, clients which could do the transformation client side didn't exist, so whether to transform client-side or server-side wasn't an issue. Recently I've been overhauling the code in order to pass transform to the client wherever possible, and I've hit two problems (i) How do I know whether the client can do transforms? Currently I'm only...
3
1565
by: toby989 | last post by:
Hi All I am completely new to this, but I was wondering if I can apply 2 xslt's subsequently to an xml, via the (client side) scripting method: http://www.w3schools.com/xsl/xsl_client.asp Like maybe: <html>
2
2358
by: milecimm | last post by:
Hello, I need some help to solve the following problem (if it is possible, that's it): I'm using a xpath expression to programatically get data from my xml file. I want to transform ONLY the resulting nodes using xslt. In my example below I only want the Academic category to be transformed. Is this possible? (please vb.net or c#). Many thanks. My xml file: <categories> <category> <categorynumber>1</categorynumber> ...
0
8454
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
8363
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
8787
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7389
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
5672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
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...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
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
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.