[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1393
  • Last Modified:

how do I pass url parameter to xsl using javascript?

I am trying to pass a url parameter to an xsl doc so that I can use that variable as a search and sort value for the transformation of an xsl doc.  I am using php and have implemented a solution using sarissa, but it does not work in Safari and Opera.  I need a simple solution that works for all browsers.
0
jzilberberg
Asked:
jzilberberg
  • 2
1 Solution
 
jzilberbergAuthor Commented:
Ok, got this all worked out.  It is really much simpler than it is made out to be when using PHP.  See my code snippet.
<?php
 
$xmlDoc = new DOMDocument;
$xmlDoc->load('xml/recipes.xml');
 
$xsl = new DOMDocument();
$proc = new XSLTProcessor;
$proc->setParameter( '', 'sort', $_GET['sort']);
$proc->setParameter( '', 'order', $_GET['order']);
$proc->setParameter( '', 'records_start', $_GET['records_start']);
$proc->setParameter( '', 'records_end', $_GET['records_end']);
$xsl->load('xml/recipes.xsl');	
$proc->importStyleSheet($xsl);
 
//This next line is the output to browser so it can be put anywhere in the html.
$proc->transformToXML($xmlDoc);
 
?>

Open in new window

0
 
jzilberbergAuthor Commented:
And her is the xsl.
<?xml version="1.0" encoding="ISO-8859-1"?>
 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:param name="sort"/>
<xsl:param name="order"/>
<xsl:param name="records_start"/>
<xsl:param name="records_end"/>
 
<xsl:template match="/">
 
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <th align="center" class="table_header" nowrap="nowrap"><a href="recipes_list.php?sort=name" class="link_white">Name</a></th>
      <th align="center" class="table_header" nowrap="nowrap"><a href="recipes_list.php?sort=type" class="link_white">Type</a></th>
      <th align="center" class="table_header" nowrap="nowrap"><a href="recipes_list.php?sort=venue" class="link_white">Venue</a></th>
      <th align="center" class="table_header" nowrap="nowrap"><a href="recipes_list.php?sort=lowfat" class="link_white">Low Fat</a></th>
      <th align="center" class="table_header" nowrap="nowrap"><a href="recipes_list.php?sort=quick" class="link_white">Quick</a></th>
      <th align="center" class="table_header" nowrap="nowrap"><a href="recipes_list.php?sort=new" class="link_white">New</a> </th>
      <th align="center" class="table_header_right" nowrap="nowrap"><a href="recipes_list.php?sort=featured" class="link_white">Featured</a></th>
    </tr>
    <xsl:for-each select="recipes/recipe">
        <xsl:sort select="(*|*/*)[name() = $sort]" order="{$order}"/>
        <xsl:if test="position() &gt;= $records_start and position() &lt;= $records_end">
            <xsl:choose>
                  <xsl:when test="position() mod 2">
                    <tr>
                      <td class="table_text" valign="top"><a href="recipes_item.php?id={id}"><xsl:value-of select="name"/></a></td>
                      <td class="table_text" valign="top" nowrap="nowrap"><xsl:value-of select="type"/></td>
                      <td class="table_text" valign="top" nowrap="nowrap"><xsl:value-of select="venue"/></td>
                      <td class="table_text" valign="top" align="center"><xsl:value-of select="lowfat"/></td>
                      <td class="table_text" valign="top" align="center"><xsl:value-of select="quick"/></td>
                      <td class="table_text" valign="top" align="center"><xsl:value-of select="new"/></td>
                      <td class="table_text_right" valign="top" align="center"><xsl:value-of select="featured"/></td>
                    </tr>
                </xsl:when>
                <xsl:otherwise>
                    <tr style="background-color: #CCCCCC;">
                      <td class="table_text" valign="top"><a href="recipes_item.php?id={id}"><xsl:value-of select="name"/></a></td>
                      <td class="table_text" valign="top" nowrap="nowrap"><xsl:value-of select="type"/></td>
                      <td class="table_text" valign="top" nowrap="nowrap"><xsl:value-of select="venue"/></td>
                      <td class="table_text" valign="top" align="center"><xsl:value-of select="lowfat"/></td>
                      <td class="table_text" valign="top" align="center"><xsl:value-of select="quick"/></td>
                      <td class="table_text" valign="top" align="center"><xsl:value-of select="new"/></td>
                      <td class="table_text_right" valign="top" align="center"><xsl:value-of select="featured"/></td>
                    </tr>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </xsl:for-each>
    </table>
 
</xsl:template>
</xsl:stylesheet>

Open in new window

0
 
waaromiknietCommented:
In this line:

<xsl:sort select="(*|*/*)[name() = $sort]" order="{$order}"/>

What does (*|*/*) mean?
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now