[xsl] Can i replace node by a variable/param!

Subject: [xsl] Can i replace node by a variable/param!
From: "Syed Abuthaheer" <abuthaheer.syed@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Aug 2001 10:37:29 +0800
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