Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a URL parameter with XSL and filtering the XML output?

Status
Not open for further replies.

Sudmill

Programmer
Apr 20, 2001
65
GB
I am trying to create XSL document that can;

1) accept a URL parameter such as C:/xml/detail.xml?TaskID=1.20
2) filter the XML data on the specified value paramter
3) work on the client side (IE 5/6) only

I have seen many methods of doing this on an ASP server, but this needs to work on the client/browser . I am having trouble find out how to parse the URL (not difficuly in itself in javascript) and pass the parameter into an XSLT variable ( shown as $CurrentTask in the code below - much more difficult! ).

How do I get my XSL document to just output all the 1.20 IDs based on the TaskID parameter ?

Short of outputing my XML into 26 different files and referencing each individually (instead of referencing a single file with a parameter), I dont know how to get this to work.

Any assitance (no matter how small) would be much appreciated!

Many thanks,

J.

---------------------------- XML style sheet --------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="detail.xsl"?>
<root>
<WSum><ID>1.10</ID><D>Information line 1</D></WSum>
<WSum><ID>1.10</ID><D>Information line 2</D></WSum>
<WSum><ID>1.10</ID><D>Information line 3</D></WSum>
<WSum><ID>1.10</ID><D>Information line 4</D></WSum>
<WSum><ID>1.20</ID><D>Information line 1</D></WSum>
<WSum><ID>1.20</ID><D>Information line 2</D></WSum>
<WSum><ID>1.20</ID><D>Information line 3</D></WSum>
<WSum><ID>1.20</ID><D>Information line 4</D></WSum>
</D></WSum>
</root>

---------------------------- XSL style sheet --------------------------------

<html>
<head>
</head>
<body>
<h2>Details</h2>
<table border="0">
<tr bgcolor="gray">
<th align="left">TID</th>
<th align="left">Description</th>
</tr>
<xsl:for-each select="root/WSum">
<xsl:choose>
<xsl:when test="(ID = $CurrentTask)">

<!-- display my table rows here -->
<td><xsl:value-of select="ID"/></td>
<td><xsl:value-of select="D"/></td>

</xsl:when>
</xsl:choose>

</xsl:for-each>
</table>
</body></html></xsl:template></xsl:stylesheet>


Cheers

John (Sudmill)
 
Maybe I don't understand what you're trying do, but anyway:
If you make am html-page, you can add javacript that loads xml- and xsl- files, and parse them.
The javascript can add any value from an input-field as parameter to the stylesheet. It can load any xml-file specified with the URL. The stylesheet can select xml-nodes based on the param, and convert them to html.
The javascript can insert the result of the transformation into the innerHTML of an element on your page.

 
So something like this:
Code:
<HTML>
<HEAD>
<script language="javascript">

function LOAD(){
	var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
	var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
	var xslProc;
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
	var id = document.getElementById("IDinput").value ;

	xmlDoc.async = false;
	xmlDoc.load("C:\\temp\\tabletree.xml");
	xslDoc.async = false;
	xslDoc.load("C:\\temp\\tabletree.xsl");
	xslt.stylesheet = xslDoc;

	xslProc = xslt.createProcessor();
	xslProc.input = xmlDoc;
	xslProc.addParameter("selectid", id);
	xslProc.transform();

	document.getElementById("results").innerHTML=xslProc.output;
}

</script>
</HEAD>
<BODY onload="LOAD();">
<input id="IDinput" />
<input id="IDbutton" type="button" onclick="LOAD();" value="Reload" />
<DIV id="results"></DIV>
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top