Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Get Variables in XSL from URL

From: Andrew Franz <afranz0@---------------->
To:
Date: 5/1/2006 12:12:00 PM
Try this:



function getURLvar(name) {
   var rs = "";
   var qparts = parent.document.location.href.split("?");
   if (qparts.length > 1) {
       var vars = qparts[1].split("&");
       for (var i=0; (i < vars.length) && (rs.length == 0); i++) {
           var parts = vars[i].split("=");
           if (parts[0].equals(name)) rs = parts[1];
       }
   }
return rs;
}

Still not sure why/how XSL comes into it - this is just JavaScript.
Better go now - before the 'topic police' get me ;-)


miouge@xxxxxxxxxxx wrote:



Bonjour Andrew Franz,



I would like use onlye a client side script :)



` bienttt, 
Cordialement Guyot Maxime.  
======= le 29/04/2006, 03:01:06 vous icriviez: =======



 



This is not strictly on-topic - however, my experience is that 
parameters are best handled outside of XSL (and server-side if possible)



The following function removes certain request parameters (in this 
example, those suffixed with .x or .y) & reassembles & reloads the URL 
without them.

Maybe you can adapt it for your needs.



function delparam() {

      var oldurl = parent.document.location.href;

      var qparts = oldurl.split("?");

      var newurl = qparts[0];

      if (qparts.length > 1) {

          // remove any "rqop" parameter, or operations will be repeated

          var vars = qparts[1].split("&");

          var sep = "?";

          for (var i=0; i < vars.length; i++) {

              var parts = vars[i].split("=");

              if ((parts[0].substr(parts[0].length-2) == ".x") || 
(parts[0].substr(parts[0].length-2) == ".y")) {

                    // do nothing

              } else {

                  newurl += sep+ parts[0]+ "="+ parts[1];

                  sep = "&";

              }

          }

      }

      parent.document.location.href = newurl;

}



Server-side, I use the following approach:

This snippet is JSP but I imagine that you can adapt it as well.

It excises the parameters named in "list" and returns the others in a 
<request> tag for further processing by XSL.



  <c:set var="list" 
value="${fn:split('spr,sprname,listinterval,listsrc', ',')}" />

  <c:set var="listplus" value="${fn:join(list,',')}," />

  <request>

      <c:forEach var="par" items="${paramValues}">

      <c:forEach var="value" items="${par.value}">

          <c:set var="keyplus" value="${par.key}," />

          <c:if test="${not fn:contains(listplus, keyplus)}">

              <jsp:element name="${par.key}">${value}</jsp:element>

          </c:if>

      </c:forEach>

      </c:forEach>

  </request>








miouge@xxxxxxxxxxx wrote:



   



Hello,
I would like to get some variables from the URL (file.xml?var1=value1&var2=value2) in the test.xml's xsl file (all of this in the client-side) and so have try this code:
<msxsl:script language="javascript" implements-prefix="prefix">
function getURLvar(name){
var params = location.search.substring(1).split("&");
var variables = new Array();
  for (i in params) {
    var segments_var = params[i].split("=");
    variables[segments_var[0]] = unescape(segments_var[1]);
  }
function setFile(file) {
  iSend = send;
}
return variables[name];
}
</msxsl:script>

and use this one to print on screen the value of the GET variables....



<xsl:value-of select="prefix:getURLvar(test)" />



But it seems not to be a good Method... and i ask if their is a better solution to achieve my goal.



Thanks, and sorry for my bad english.



Maxime G.

   




= = = = = = = = = ========= = = = = = = = = = =
			
miouge
miouge@xxxxxxxxxxx
30/04/2006


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent