xsl-list
[Top] [All Lists]

[xsl] Passing javascript variable as parameter to XSL

2006-04-26 02:26:40
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">
<html><HEAD></HEAD><body>
<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. 
 //document.write(varpage); 
    var xslt = new ActiveXObject("Msxml2.XSLTemplate");
    var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
    var xslProc;
    xslDoc.async = false;
    xslDoc.resolveExternals = false;
    xslDoc.load("../scripts/hereName.xsl");
    xslt.stylesheet = xslDoc;
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
    xmlDoc.load("../Content/domestic_portfolio.xml");
    xslProc = xslt.createProcessor();
    xslProc.input = xmlDoc;
    xslProc.addParameter("partnername", varpage);
    xslProc.transform();
    document.write(xslProc.output);
</script>
</div></body>

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<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"/>
 </td></tr>
    </xsl:for-each>
</table><br />
</td></xsl:for-each>
</tr></table>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

The XML file I'm using is available at:
http://web.aanet.com.au/HairyBeast/rws/Content/domestic_portfolio.xml
... 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>