This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Can i replace node by a variable/param!
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Can i replace node by a variable/param!
- From: "Syed Abuthaheer" <abuthaheer dot syed at infoworld dot com dot my>
- Date: Wed, 15 Aug 2001 10:37:29 +0800
- References: <8900656CF898D111B75700805FE66A761096C454@aupoza438.btal.btco.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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