Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 18th, 2006, 04:10 PM
Authorized User
 
Join Date: Jun 2003
Location: pgh, pa, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to drdexter33 Send a message via MSN to drdexter33
Default Javascript with XSL

I need to pass a value from my XSL file to a JavaScript function and can't quite figure it out.

Example:

--------------------------------------------------------------

<xsl:for-each select="NewDataSet/Cases">

<tr>

//CELL ONE

<td>

<xsl:value-of select="ViewDetails" />


<a href="javascript:ViewDetails()">View Details</a>

</td>

<td>

//CELL TWO



<xsl:value-of select="MRN" />



</td>

//CELL THREE

<td>



<xsl:value-of select="AccessionNumber" />



</td>

</tr>

--------------------------------------------------------------

In the ViewDetails function:

<a href="javascript:ViewDetails()">View Details</a>

I would like to pass these values:

<xsl:value-of select="MRN" />

<xsl:value-of select="AccessionNumber" />

Is this possible?



Thanks.
Reply With Quote
  #2 (permalink)  
Old January 18th, 2006, 05:42 PM
Registered User
 
Join Date: Jan 2006
Location: High wycombe, Bucks, United Kingdom.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not an xsl expert but i was browsing and thought you might appreciate a reply at this time.

I would do this by setting up a variable to contain the value as follows

<xsl:variable name="Accession">
<xsl:value-of select="AccessionNumber"/>
</xsl:variable>

Position this at the start of the template.

the value can be inserted into your javascript as follows

...javascript:ViewDetails( {Accession} ); ...


hope this works for you


Reply With Quote
  #3 (permalink)  
Old January 19th, 2006, 01:36 PM
Authorized User
 
Join Date: Jun 2003
Location: pgh, pa, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to drdexter33 Send a message via MSN to drdexter33
Default

Hey petebone


Thanks for your reply

I probably should've prefaced what I was attempting to do in my original post.

What I am attempting to do is utilize the ClientCallback functionality in the ASP.Net 2.0 framework to minimize postbacks and take care of most of this stuff asynchronously.

In doing this, of course there is the idea of instead of using a server side GridView control to handle my data display, we're using JavaScript and the MSXML parser to handle the XML feed back from the web service.

The web service that returns an XML string from a dataset is using the XMLDataDocument object to convert the dataset to an xml string like this:

---------------------------------------------------------

da.Fill(ds,startRec,maxRec,"Cases");

DataColumn viewDetails = new DataColumn("viewDetails");

ds.Tables["Cases"].Columns.Add(viewDetails);

XmlDataDocument xml = new XmlDataDocument(ds);

return xml.OuterXml.ToString();

---------------------------------------------------------

As you'll notice in the da.fill() call, I'm using startRec, maxRec as parameters.

This is to handle paging, which the GridView control handles for you, but if you're doing this kind of stuff yourself, i guess this is a way to handle it.

I think a more efficient way to do this would be to just dump a dataset into a client side array and page it on the client, but what the heck...for now it works, and since the callback runs asynchronously, for now, you can't notice any performance hit...I'll probably change this later for scalabilty.

Well when the web service returns the XML string:

---------------------------------------------------------

return xml.OuterXml.ToString();

---------------------------------------------------------

The javascript parses the XML and XSL like this:

---------------------------------------------------------

function GetCases(xmlString, context){

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

try

{

xmlDoc.loadXML(xmlString) ;

}

catch(err)

{

alert(err.description);

}


//Load XSL

var XSLDoc = new ActiveXObject("Microsoft.XMLDOM");

XSLDoc.async = false

XSLDoc.load("xsl/cases.xsl");

document.all.divCases.innerHTML = xmlDoc.transformNode(XSLDoc);

}

---------------------------------------------------------

So here's where we come to our XSL/Javascript problemo...

---------------------------------------------------------

The XML is returning all the columns and rows I need to display in an XML/XSL transformed format to a div tag in the HTML page, as the Javascript indicates in the last line above:

---------------------------------------------------------

document.all.divCases.innerHTML = xmlDoc.transformNode(XSLDoc);

---------------------------------------------------------

But since I needed a way to provide the user to select a row [for a master/detail record], I had to add a hyperlink that had JavaScript client side functionality so I can grab a primary key value when the user clicks on it...and get the associated detail records..

sort of analagous to the select in GridView...



This is where the problem with XSL and JavaScript comes in:

I needed a way to add a column with a hyper link that calls a JavaScript function and passes a composite key value. In my case MRN and Accession number. So here's how I did it:

---------------------------------------------------------

<td>





<xsl:variable name="delim">

<xsl:text>~</xsl:text>

</xsl:variable>




<xsl:variable name="quot">

<xsl:text>'</xsl:text>

</xsl:variable>



<xsl:variable name="CompositeKey" xml:space="default">

<CompositeKey>

<xsl:copy-of select="$quot" />

<xsl:value-of select="MRN" />

<xsl:copy-of select="$delim" />

<xsl:value-of select="AccessionNumber" />

<xsl:copy-of select="$quot" />

</CompositeKey>

</xsl:variable>



<a href="javascript:ViewDetails({$CompositeKey})">Vie w Details</a>





</td>

---------------------------------------------------------

This <td></td> cell is the first column.

For the remaining columns I just did a

<xsl:value-of select="xmlCol_1" />

<xsl:value-of select="xmlCol_2" />

etc.



Thanks Again.



God Bless



Doug































--------------------------------------------------------------------------------
Douglas R. Dexter
Programmer III
Radiology Informatics
IMITS
The University Of Pittsburgh Medical Center
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL & JavaScript Ryan Moore XSLT 1 October 9th, 2007 01:36 PM
xsl javascript problem smi13y XSLT 1 December 26th, 2006 07:27 PM
XSL maybe javascript. suri_1811 XSLT 1 November 3rd, 2006 12:20 PM
External JavaScript with XSL NEO1976 XSLT 2 September 5th, 2006 07:19 AM
How to use Javascript in XSL umeshayk XSLT 3 January 16th, 2004 11:33 AM



All times are GMT -4. The time now is 08:21 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.