1

I am trying to retrieve parameter values from the URL using XML but I can't seem to retrieve the data. Kindly check the photo I posted below to get a clearer view: enter image description here

From what I understand, the < xsl:param name="page" > will automatically retrieve the value from the URL. I decided to put a default value of 666, however I tried testing it through my WAMP server and added the parameter page=1. I was expecting that my XSL would display the value rather than the 666. Am I missing something here?

I've been following a XSLT pagination tutorials and most I found does it this way (to keep track the current page) and I'm no sure why it isn't working for me. Any help would be greatly appreciated. Thanks.

Here is how my XSL code looks like (removed all my code and placed only the part I'm concerned with):

<?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" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<xsl:template match="/">
    The value of current page is: 
    <xsl:value-of select="$currentPage" />
</xsl:template>
</xsl:stylesheet>

Here's how my XML looks like, nothing special but just links to the XSL:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="laptops.xsl"?>
<laptops>
</laptop>

So I was expecting that when I call my XML file through the browser with with a URL parameter of "?page=1", it gets rendered with XSL, I should be able to retrieve the value '1' and the XSL will display it. However I'm not able to retrieve any value from the URL.

it2051229
  • 339
  • 3
  • 13
  • Don't post your code as an image. Post the XSL, input XML and expected output as code blocks. If they're too long then create a small testcase that demonstrates the problem. Finally, why do you think a URL query-string is passed as a parameter to the XSL transform? – Jim Garrison Feb 27 '16 at 08:02
  • Sorry about that Jim. I tried to get only parts on the code that matters. I am passing a query string to make my pagination dynamic so I thought of keeping the current state of the current page as a query string (the previous and next page are pre-calculated at some part of the code in the XSL. Note that I am only using XML, HTML, and XSL here and I do not want to use or include server side languages and client side language like JavaScript. I'm trying to see how far I can go with just XSL. – it2051229 Feb 27 '16 at 08:11
  • Are you depending on the browser to invoke the XSL transform on the XML it receives, or is that being done server-side? If you want any help we are really going to have to see a self-contained set of XML and XSL that demonstrates the problem, with an explanation of where the XSL transform is being invoked and how you expect to get the query-string passed as an XSL parameter. – Jim Garrison Feb 27 '16 at 08:15
  • Hi Jim, I believe it is being done server-side because I am using a locally hosted server (WAMP). And I am accessing the XML file through the localhost web address. – it2051229 Feb 27 '16 at 08:25
  • 2
    That won't cause a server-side transformation. When you access the xml file through your browser, the server will deliver the file to the browser. Any transformation will be done client-side. It should be possible to configure the server to do a server-side transformation and deliver the transformed results upon a request, but unless you have done that, the browser will be doing the transformation. Just using a locally hosted server won't change that. – Matthew Feb 27 '16 at 09:28
  • 2
    What has given you the impression that your environment will supply a URI as the value of a parameter named `page`? (And if that is your impression, why does your stylesheet look for a parameter named `currentpage` instead of `page`?) It's entirely possible that the WAMP package sets up an environment in which one or the other of these parameters is passed to the XSLT processor, but it's not a universal law, or even a particularly widely known practice. I've added the wampserver tag, since it seems to be a wamp question. – C. M. Sperberg-McQueen Feb 27 '16 at 16:15
  • 2
    If you ever find a way to transmit an output value of an XSLT stylesheet back as an input value to the same stylesheet - all client side - I'd gave you and the devs kudos. That would be great. It would revolutionize the WWW. So far, I have to do it with a PHP echo server transforming URLs to XML parameters :-( – zx485 Feb 27 '16 at 19:49
  • Ok thanks guys. Based on zx485's answer, It seems like it's not possible and I thought URL parameters in xsl can be retrieved without the help of any serverside language. If ever I will include javascript or server side language to this, I guess I'll do my pagination programmatically the common way and forget xsl. I mean I'm trying to weigh things how powerful and independent xsl would be. Anyways, thanks again, I'm closing this experiment for now. – it2051229 Feb 27 '16 at 23:50

0 Answers0