Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Javascript in XSL

Status
Not open for further replies.

drdexter33

Programmer
Jun 11, 2003
17
0
0
US
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

<font face="verdana" size="1" align="middle">

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

</font>

</td>

//CELL THREE

<td>

<font face="verdana" size="1" align="middle">

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

</font>

</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.
 
Like this.
[tt]
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat('javascript:ViewDetails(','&#34;',MRN,'&#34;',',','&#34;',AccessionNumber,'&#34;',')')" />
</xsl:attribute>
<xsl:text>some description</xsl:text>
</a>
</td>
[/tt]
 
Here is another solution:

<a href="javascript:ViewDetails('{MRN}','{AccessionNumber}')">View Details</a>
 
Hey everyone.

Thanks for your replies

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.

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, I had to add a hyperlink that had JavaScript client side functionality so I can grab a value when the user clicks on it...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>

<font face="verdana" size="1" align="middle">

<!-- Variable for delimiter -->

<xsl:variable name="delim">

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

</xsl:variable>


<!-- Variable for single quote -->

<xsl:variable name="quot">

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

</xsl:variable>

<!-- Variable for composite key -->

<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>

<!-- this function is implemented in ViewCases.aspx -->

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



</font>

</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 for your reply...

Here's what I finally got to work.

<td>

<font face="verdana" size="1" align="middle">

<!-- Variable for delimiter -->

<xsl:variable name="delim">

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

</xsl:variable>


<!-- Variable for single quote -->

<xsl:variable name="quot">

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

</xsl:variable>

<!-- Variable for composite key -->

<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>

<!-- this function is implemented in ViewCases.aspx -->

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



</font>

</td>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top