[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Passing javascript variable as parameter to XSL

Subject: Passing javascript variable as parameter to XSL
From: "Spencer Easterbrook" <s.easterbrook@xxxxxxxxxxxx>
Date: Wed, 26 Apr 2006 10:26:26 +0100
javascript variable parameters
Hi all,

Firstly, I confess ... I'm relatively new to XSL, but what I have been
able to learn and use has been thanks largely to posts on lists and
forums, and so I'm sure that this is the best place to ask my question.
Forgive me for what is, I'm sure, a reasonably simple problem!

Problem:  I have an HTML page called 'test.html'.  This page is only a
test page to sort out this functionality, but what it should do is
return a table consisting of elements from the selected record in the
XML file.

The code for the html file is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<div id="Ranges" class="varRangeDisplay">
<script language="javascript">
   var URL1 = unescape(location.href) // get current URL in plain ASCII
   var xstart1 = URL1.lastIndexOf("/") + 1
   var xend1 = URL1.length
   var varpage = URL1.substring(xstart1,xend1);

 //  varpage now contains the page name.
    var xslt = new ActiveXObject("Msxml2.XSLTemplate");
    var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
    var xslProc;
    xslDoc.async = false;
    xslDoc.resolveExternals = false;
    xslt.stylesheet = xslDoc;
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
    xslProc = xslt.createProcessor();
    xslProc.input = xmlDoc;
    xslProc.addParameter("partnername", varpage);

Note:  The javascript variable I am trying to pass is called "varpage"
and evaluates (successfully) to the name of the html document (in this
case 'test.html').  I am using addParameter to add a parameter called
"partnername" to the xslProc transformation to use as a XSL:PARAM in the
XSL file.  But it's not working ... the XSL I have done is:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
<xsl:output method="html" encoding="iso-8859-1"/>
<xsl:param name="partnername"></xsl:param>
<xsl:template match="rwsdomesticportfolio/partner">
<xsl:if test="varpage='$partnername'">
<table border="1"><tr>
<xsl:for-each select="portfolio/range">
 <td valign="top">
  <xsl:value-of select="rangename"/>
<table border="1">
  <xsl:for-each select="varietal">
  <tr><td align="center">
 <xsl:element name="IMG">
  <xsl:attribute name="SRC">
  <xsl:value-of select="bottleshot"/></xsl:attribute>
  <xsl:attribute name="BORDER">0</xsl:attribute>
 </xsl:element><br />
 <xsl:value-of select="varietalname"/>
</table><br />

The XML file I'm using is available at:
... it's fairly long so I didn't put it in here.  The important piece is
an element called <varpage> within each <partner> record which I'm using
to test against in the XSL.

Basically, I'm getting nothing returned, which means that either the
xsl:if test is failing or the parameter is not being passed.

What's really bugging me is that if I hardcode the page name in the XSL,
then it works fine (e.g. <xsl:if test="varpage='test.html">, or any
other valid varpage value in the XML)!!

I will be eternally grateful if anyone is able to spot the problem and
let me know how to fix it!!

Regards, Spencer

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.