• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Manipulating XML string using JavaScript in XSL

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I need to manipulate a XML string which is thrown by server with XSL reference embedded. I need to insert a piece of Code written in JavaScript to my XSL file to traverse the string to match an existing string of data with one at a node and collect the chaild nodes of the same. Please note that I have a XML string in the memory.
------------------
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds complicated... My friend�s karate instructor used to say: "if you do something and it is difficult, know: you do it wrong. It shouldn�t be difficult". Perhaps you should formulate what you want not in terms if "JavaScript" and "XSLT", but in terms of your goals: what do you want to get?
If you want to select all nodes with specific name you can pass it in XSLT as a parameter and then select all matching nodes with expression
select="*[name(.)=$parameter]"
You do not need JavaScript to do it.
"XML string which is thrown by server with XSL reference embedded" � you mean that you have both XML and XSLT written, and you want somehow modify XSLT to get the result other, than it produces? Then it is easier to simply apply another XSLT. I believe you can call XSLT stylesheet dynamically in IE, even if XML document specifies one.
 
Krishna Mudda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mapraputa Is:
Sounds complicated... My friend�s karate instructor used to say: "if you do something and it is difficult, know: you do it wrong. It shouldn�t be difficult". Perhaps you should formulate what you want not in terms if "JavaScript" and "XSLT", but in terms of your goals: what do you want to get?
If you want to select all nodes with specific name you can pass it in XSLT as a parameter and then select all matching nodes with expression
select="*[name(.)=$parameter]"
You do not need JavaScript to do it.
"XML string which is thrown by server with XSL reference embedded" � you mean that you have both XML and XSLT written, and you want somehow modify XSLT to get the result other, than it produces? Then it is easier to simply apply another XSLT. I believe you can call XSLT stylesheet dynamically in IE, even if XML document specifies one.


My friend,
Thanks for ur suggestion. I have no idea how I can dynamically call another XSLT in IE. I can't modify the XML formatted string as it is coming from server. So I have only one XSL which has its reference in XML and I need to modify the same. So please suggest some way if not JavaScript to get the work done.

------------------
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a working example how XSLT can be applied dynamically. (all code is in control.htm
It should be something like:
source = new ActiveXObject("Microsoft.XMLDOM");
source.async = false;
style = new ActiveXObject("Microsoft.XMLDOM");
style.async = false;
source.load(�myXML.xml�);
style.load (�myXSLT.xsl�);
source.transformNode(style);
you can use their JavaScript as a prototype
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!