Re: [xsl] passing parameter via javascript

Subject: Re: [xsl] passing parameter via javascript
From: Claudio Russo <claudio_russo@xxxxxxxxx>
Date: Tue, 24 Jun 2003 09:22:52 -0700 (PDT)
Lo Eric,

I hope de next works for you (it does in my
application):

=====================================================
1) The next body HTML calls a javascript routine
called "Titulos" which is at the end of the HTML.

<body onLoad="Titulos()"><table border="0"
width="100%" cellspacing="1">
  <tr>
    <td width="100%">
      <div align="center">
        <center><table border="0" width="100%"
cellspacing="4" height="592">
        <tr>
          <td width="100%" align="center" height="1">
                <!-- XML ID="xmlRanking"
SRC="ranking_sorter.xml"></XML -->
                     <DIV ID="divResults" /></DIV>
          </td>
        </tr>

=====================================================
2) This is the routine at the end of the HTML. See the
"addParameter" instruction where I defined first the
name of the variable inside the Stylesheet, second the
value that I passing to it.

<script language="JavaScript">
  var xmlDOM, xslDOM;
	
  var xslt, xml, xslTemp, xslProc;
  var xslt_table, xml_table, xslTemp_table,
xslProc_table;

  
  // variable para dejar los resultados de la
extracción de parámetros en la linea de 
  // invocación del HTML.
  var srchData = getSearchAsArray();
  
  var sortVal;
  
  function Titulos()
  {
     xml  = new
ActiveXObject("Msxml2.DOMDocument.4.0");
     xml.async=false;
     xml.load("ranking_sorter.xml");

     xslt = new
ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
     xslt.async=false;
     xslt.load(XSLHeader);

     xslTemp = new
ActiveXObject("Msxml2.XSLTemplate.4.0");
     xslTemp.stylesheet = xslt;
     
     xslProc = xslTemp.createProcessor();
     xslProc.input = xml;
     xslProc.addParameter("anio", srchData["anio"]);
     xslProc.addParameter("sexo", srchData["sexo"]);
     xslProc.addParameter("categ", srchData["categ"]);

     xslProc.transform;
     divResults.innerHTML = xslProc.output;
     
     Ranking("posicion", "", "number")
     
  }

</script>


</body>

</html>

=====================================================
3) This is the stylesheet code where the parameter
lives. You can use it in an xsl:if instruction and
include/call one or other stylesheet using the $ sign
before the name of the parameter.

<XML ID="XSLHeader">
  <xsl:stylesheet version="1.0"  
   	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   	xmlns:js="javascript:code"
   	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:ms="urn:schemas-microsoft-com:xslt"
	xmlns:fo="http://www.w3.org/1999/XSL/Format";>

	<msxsl:script language="javascript"
implements-prefix="js">
	   function factorial(n)
	   {
			if (n == '1')
				{ return ( 1 ) }
			else 
				{ return ( n * factorial(n - 1) ) }
    	}
    	
    	function totalReg(node, anio, sexo, categ)
    	{
      		total = 0;
      //	return "/jugador[sexo='" + sexo + "' and
categoria=" + categ + " and anio=" + anio + "]"
          jugadores =
node.selectNodes("/portfolio/[sexo='" + sexo + "' and
categoria=" + categ + " and anio=" + anio + "]");
          for (v = jugadores.nextNode(); v; v =
jugadores.nextNode())
            total += 1;
          return formatNumber(total, "#");
    	}

	</msxsl:script>

   		<xsl:param name="sexo"/>
   		<xsl:param name="categ"/>
   		<xsl:param name="anio"/>
   		
		<xsl:template match="portfolio">
		
    		<head>
      		</head>
        	<table border="2" width="100%" height="6">
          		<tr>
            		<td class="bg">
              		<H1><xsl:value-of
select="description"/> del <xsl:value-of
select="$anio"/> - <xsl:value-of select="$categ"/>
Años, 
                 			<xsl:choose>
      							<xsl:when
test="$sexo='V'">Varones</xsl:when>
								<xsl:otherwise>Damas</xsl:otherwise>
							</xsl:choose>
							
   						</H1>
              		<H3>Actualizado el
<xsl:apply-templates select="date"/>
						</H3>
						<DIV>Total de Jugadores: <B><xsl:value-of
select="count(jugador[sexo=$sexo and categoria=$categ
and anio=$anio])"/></B></DIV>
						<P>Presione sobre los encabezados para ordenar
por dicho campo ascendente o descendentemente.</P>
            		</td>
          		</tr>
       	</table>
  		</xsl:template>
  
		<xsl:template match="date">
    		<xsl:value-of select="ms:format-date(., 'd',
SP_ar)"/> de <xsl:value-of select="ms:format-date(.,
'MMMMM, yyyy', SP_ar)"/>
			a las <xsl:value-of select="ms:format-time(.,
'hh:mm tt')"/>
		</xsl:template>

	</xsl:stylesheet>
</XML>

=====================================================

--- Eric K Taylor <eric_k_taylor@xxxxxxxx> wrote:
> 
> in one frame, javascript opens an xml file in
> another frame:
> <a
>
href="javascript:{parent.right.location.href='file.xml';}>...
> 
> However, I want to be able to:
> A) pass a parameter that tells whether to transform
> file.xml with fileA.xsl or fileB.xsl
>     and/or
> B) pass a parameter that gets passed on to the
> stylesheet (since I have the xsl file set up to deal
> with a passed parameter.
> 
> Is this do-able?
> 
>
________________________________________________________________
> The best thing to hit the internet in years - Juno
> SpeedBand!
> Surf the web up to FIVE TIMES FASTER!
> Only $14.95/ month - visit www.juno.com to sign up
> today!
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


=====
Regards, Claudio.

IT Consultant.
Buenos Aires, Argentina.
e-mail: claudio_russo@xxxxxxxxx


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread