I'm almost done with this application, which merges an XML doc and XSLT stylesheet through an ASP.NET page to form an XHTML resulting page. I've successfully been able to do almost everything except for the addition of a dynamic xsl:sort method (similar to an ASP.NET sortable DataGrid)
I've added empty xsl:parameters to the XSLT stylesheet, passed those 3 variables into the querystring attached to the ASP.NET page's URL, and I added a script within the ASP.NET page to transform those paramaters to whatever's contained in the querystring. But the parameter transformation is not working, and each of the parameters is storing the complete URL & querystring instead of each specified parameter.
So I'm attaching the code that I'm using in hopes that someone can see what step I'm missing. Any & all constructive criticism is welcome. Thanks.
XML doc (shortened example):
<formsdocs>
<form>
<title>Form 1</title>
<url>http://DOMAIN/DIRECTORY/docs/pdf/FILENAME.pdf</url>
<type>internal</type>
<format>pdf</format>
<size>2 KB</size>
<dept>IT</dept>
<div />
</form>
<form>
<title>Form 2</title>
<url>http://DOMAIN/DIRECTORY/SUBDIRECTORY/FILENAME.html</url>
<type>internal</type>
<format>html</format>
<size>5 KB</size>
<dept>AS</dept>
<div />
</form>
<form>
<title>Form 3</title>
<url>http://www.OTHERWEBSITE.com</url>
<type>external</type>
<format>html</format>
<size />
<dept />
<div />
</form>
</formsdocs>
XSLT stylesheet:
Code:
<?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="sortBy" select="''" />
<xsl:param name="sortType" select="''" />
<xsl:param name="sortOrder" select="''" />
<xsl:variable name="pageURL">http://DOMAIN/DIRECTORY/FILENAME.aspx</xsl:variable>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Forms & Documents</title>
</head>
<body>
<h1>Forms & Documents</h1>
<br />
<br />
<table class="navyblueborder" width="95%" align="center">
<tr bgcolor="#333366" class="whiteheader">
<th align="left">
<xsl:text>Form/Document </xsl:text>
<a class="white" href="{$pageURL}?sortBy=title&sortType=text&sortOrder=ascending">[ASC</a>
<xsl:text> | </xsl:text>
<a class="white" href="{$pageURL}?sortBy=title&sortType=text&sortOrder=descending">DESC]</a>
</th>
<th align="left">
<xsl:text>Department </xsl:text>
<a class="white" href="{$pageURL}?sortBy=dept&sortType=text&sortOrder=ascending">[ASC</a>
<xsl:text> | </xsl:text>
<a class="white" href="{$pageURL}?sortBy=dept&sortType=text&sortOrder=descending">DESC]</a>
</th>
<th align="center">
<xsl:text>Type </xsl:text>
<a class="white" href="{$pageURL}?sortBy=type&sortType=text&sortOrder=ascending">[ASC</a>
<xsl:text> | </xsl:text>
<a class="white" href="{$pageURL}?sortBy=type&sortType=text&sortOrder=descending">DESC]</a>
</th>
<th align="center">
<xsl:text>Format </xsl:text>
<a class="white" href="{$pageURL}?sortBy=format&sortType=text&sortOrder=ascending">[ASC</a>
<xsl:text> | </xsl:text>
<a class="white" href="{$pageURL}?sortBy=format&sortType=text&sortOrder=descending">DESC]</a>
</th>
<th align="center">
<xsl:text>File Size </xsl:text>
<a class="white" href="{$pageURL}?sortBy=size&sortType=text&sortOrder=ascending">[ASC</a>
<xsl:text> | </xsl:text>
<a class="white" href="{$pageURL}?sortBy=size&sortType=text&sortOrder=descending">DESC]</a>
</th>
<th align="center">
<xsl:text>sortOrder</xsl:text>
</th>
</tr>
<xsl:for-each select="formsdocs/form">
<xsl:choose>
<xsl:when test="$sortOrder = 'ascending'">
<xsl:apply-templates select="$sortBy">
<xsl:sort select="$sortBy" data-type="text" order="ascending" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$sortBy">
<xsl:sort select="$sortBy" data-type="text" order="descending" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
<tr>
<td align="left"><a href="{url}" target="{target}"><xsl:value-of select="title" /></a></td>
<td align="left"><xsl:value-of select="dept" />
<xsl:choose>
<xsl:when test="div != ''">
(<xsl:value-of select="div" /> Division)
</xsl:when>
</xsl:choose>
</td>
<td align="center"><xsl:value-of select="type" /></td>
<td align="center"><xsl:value-of select="format" /></td>
<td align="center"><xsl:value-of select="size" />
<xsl:choose>
<xsl:when test="size = ''">
---
</xsl:when>
<xsl:otherwise>
KB
</xsl:otherwise>
</xsl:choose>
</td>
<td align="left"><a href="*[name() = $sortOrder]" target="{target}"><xsl:value-of select="title" /></a></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ASP.NET/VB.NET doc:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
'Load XML
Dim xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load("http://DOMAIN/DIRECTORY/FILENAME.xml")
'Load XSL
Dim xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("http://DOMAIN/DIRECTORY/FILENAME.xsl")
'Pull in querystring variables
Dim sortBy_qs = Request.QueryString("sortBy")
Dim sortType_qs = Request.QueryString("sortType")
Dim sortOrder_qs = Request.QueryString("sortOrder")
Dim sortBy
sortBy = xsl.selectSingleNode("//xsl:param[@name='sortBy']")
sortBy.SetAttribute("select", sortBy_qs)
Dim sortType
sortType = xsl.selectSingleNode("//xsl:param[@name='sortType']")
sortType.SetAttribute("select", sortType_qs)
Dim sortOrder
sortOrder = xsl.selectSingleNode("//xsl:param[@name='sortOrder']")
sortOrder.SetAttribute("select", sortOrder_qs)
'Transform file
Response.Write(xml.transformNode(xsl))
%>
KWilliams