[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Can i replace node by a variable/param!

Subject: Can i replace node by a variable/param!
From: "Syed Abuthaheer" <abuthaheer.syed@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Aug 2001 10:37:29 +0800
javascript replace node
hi all,
i am facing a problem in XSL.
I am passing a variable from javascript to xsl. I am able to retrieve the
value perfectly. i want to use the passed variable as node. herewith i am
pasting my code.

Pl. refer test.xml and test.xsl code pasted at the bottom

<xsl:param name="str"/><!--here i am retrieving the value of "str" as "name"
from javascript-->
<xsl:for-each select="root/address">
     <xsl:value-of select="name"/>
<!--I want to display all the values of root/address/name. At the same time
i want  to use the passed variable "str" instead of hardcoding "name". In my
actual application, i need to display dynamically--><br/>
     </xsl:for-each>

your assistance is highly appreciated.
thanks in advance.
regards,
syed.

My detailed code is here.
test.htm
<html>
<head>
  <script language="javascript">
 function callfun()
 {
  try{
  var xmlDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
  var xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
  xmlDoc.async = false
  xslDoc.async = false

    xmlDoc.load ("test.xml")
    xslDoc.load ("test.xsl")

  var tem = new ActiveXObject("MSXML2.XSLTemplate");
  tem.stylesheet = xslDoc;
  var proc = tem.createProcessor();
  proc.addParameter("str","name");//here i am passing the value to my
xsl("name" is a node value in my XML-Pl refer test.xml)
  proc.input = xmlDoc;

  //Transform the document
  proc.transform();
  var str = proc.output;

  //replace it in the addrTable (DIV) tag
  document.all.addrTable.innerHTML = str
  }catch(exception){}
 }
  </script>
</head>
<body>
<DIV id="addrTable">
  <input type="button" name="click" value="Click" onClick="callfun()">
  </DIV>
</body>
</html>

test.xml
 <?xml version="1.0" encoding="UTF-8"?>
<root>
 <address>
  <name>A</name>
 </address>
 <address>
  <name>B</name>
 </address>
 <address>
  <name>C</name>
 </address>
</root>

test.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version =
"1.0" >
<xsl:param name="str"/><!--here i am retrieving the value of str as
"name"-->
 <xsl:template match="/">
  <html>
   <body>
    <xsl:for-each select="root/address">
     <xsl:value-of select="name"/><!--I want to display all the values of
root/address/name. At the same time
i want  to use the passed variable "str" instead of hardcoding as "name". In
my
actual application, i need to display dynamically--><br/>
     </xsl:for-each>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.