473,503 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to pass a variable to xsl and how xsl can recognise it?

renoua
11 New Member
hello,
I have this javascript code
Expand|Select|Wrap|Line Numbers
  1. function displayResult2(id) 
  2. {
  3. xml=loadXMLDoc("anna.xml");
  4. xsl=loadXMLDoc("c011.xsl");
  5.  
  6. // code for IE
  7. if (window.ActiveXObject)
  8.   {
  9.   ex=xml.transformNode(xsl);
  10.   document.getElementById("right").innerHTML=ex;
  11.   }
  12. // code for Mozilla, Firefox, Opera, etc.
  13. else if (document.implementation && document.implementation.createDocument)
  14.   {
  15.   var xsltProcessor=new XSLTProcessor();
  16.   xsltProcessor.importStylesheet(xsl);
  17.   resultDocument = xsltProcessor.transformToFragment(xml,document);
  18.  document.getElementById("right").appendChild(resultDocument);
  19.   }
  20. }
and I want to pass the variable id at the c011.xsl
after that.. how c011.xsl can recognize that variable? what's the syntax?
any help would be appreciated :)
Jun 22 '10 #1
13 2953
Dormilich
8,658 Recognized Expert Moderator Expert
setting parameters in Mozilla
Jun 22 '10 #2
renoua
11 New Member
very usefull article.. thnx!
so, i wrote that line of code :
Expand|Select|Wrap|Line Numbers
  1. xsltProcessor.setParameter(null, "id", xsl);
I don't know why i put xsl in the parameters but alternatively it's not working.

I added the xsl param at c011.xsl
Expand|Select|Wrap|Line Numbers
  1. <xsl:param name="id"/>
but the xsl if condition does not work :(

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="did/unitid='$id'">
  2. xsl tranformation
  3. </xsl:if>
  4.  
maybe the syntax is wrong..
but I don't know how to solve this.. i google it i changed it hundred of times but still failure...
Jun 22 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
try
Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="did/unitid/text() = $id">
Jun 23 '10 #4
renoua
11 New Member
No, it doesn't work..
I added ' ' but still nothing..

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="did/unitid/text() = '$id'">
maybe the variable from javascript didn't pass successfully?
Jun 23 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
I deliberately omitted the ' '.

further, what does "/did/unitid" return normally, a node or a nodeset?
Jun 23 '10 #6
renoua
11 New Member
With or without ' '
I don't see xsl transformation
Jun 23 '10 #7
Dormilich
8,658 Recognized Expert Moderator Expert
does it work, when you do it manually?
Jun 23 '10 #8
renoua
11 New Member
A node,
well when i choose one of 106 unitid, my xml file has,
for example 'L7346'

"/did/unitid='L7346'"
I see the result i want.
Jun 23 '10 #9
Dormilich
8,658 Recognized Expert Moderator Expert
well, I’ve never done XSLT in JavaScript (for obvious reasons) so I’m not of much help in debugging this. Personally, I prefer server-side XSLT, esp. since AJAX (target.appendChild(XHR.responseXML.documentElement );).
Jun 23 '10 #10
renoua
11 New Member
well,
I suppose I have made wrong the syntax of this

xsltProcessor.setParameter(null, "id", xsl);

anyway, thank you very very much for your interest and help ! I hope to find a solution asap.. :)
Jun 23 '10 #11
Dormilich
8,658 Recognized Expert Moderator Expert
now that you mention it, yes. (look at the example provided) the 3rd parameter of .setParameter() is the value of the parameter, where you passed the XSL file.
Jun 23 '10 #12
renoua
11 New Member
well yes the syntax was wrong

i corrected the code but

id is a variable but when i write it like that:
xsltProcessor.setParameter(null, "uid", "id")

it passes to c011.xsl like a static text "id" that's why I could not see result the condition was always false


do you know how can i pass it dynamically?
what i Have to write at the 3rd parameter exactly?
Jun 23 '10 #13
renoua
11 New Member
I found it i didn't need " ".

so the right syntax is
xsltProcessor.setParameter(null, "uid", id);
Jun 23 '10 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2337
by: weiwei | last post by:
Hi all I am having trouble, let's say, I have a form text field, and I want to pass it to the next page, however, I don not want to use submitted button, instead I want to have a variable in link...
4
9615
by: Wayne Baswell | last post by:
I want to pass a date variable to a sql statement from Crystal Reports. The part of the query accepting the variables looks like: "Calendar_Date between To_Date('1-JUN-03','mm/dd/yy') and...
4
6059
by: Sharon | last post by:
Hi! After transforming XML to CSV format I open an HTA to save the CSV to the client. All goes well, the function looks like this: function buttonExportClick() { var xslt = new...
5
7068
by: GB | last post by:
Hello: In my MS Access project I have two objects - my form and my report. I need to pass variable value from Command_click procedure of my form to Report_open procedure of my report. How can I...
1
3122
by: Ben Kial | last post by:
I'd like to write a wrapper function "mysprintf(char *buffer, char *format, ....)" which calls sprintf(). My question is how can I pass variable argument in mysprintf() to sprintf(). Thanks in...
8
6563
by: darrel | last post by:
I'm still trying to fully understand how best to pass variables between pages/usercontrols/each other. On a current site I've done, I've had one userControl do the logic and set the variable,...
1
2410
by: dollar | last post by:
I want to ask what is the best way to pass variable between asp.net we pages, and user controls , any examples - dolla -----------------------------------------------------------------------...
1
7730
by: drec | last post by:
I need to pass a variable from script1.php to script2.php. The problem is that these scripts use frames and therefore I am able to pass the variable through the URL. It also does not use forms to...
1
4047
by: vijaynarang | last post by:
strCmdLine = " " + " -o restore -url " + sSitePath + "/sites/" + sToplevelSiteName + " -filename " + sFileName+ " -overwrite "; process1 =...
12
6821
by: simon2x1 | last post by:
i have a page which is home.php on that page i have a CSS tab which is tab1 and tab2 on that page in both tabs i have a link called next that pass variable to the next page (<a...
0
7199
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,...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
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...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
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...
0
3162
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...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.