Jump to content

XInclude


Recommended Posts

ok its working in IE nowwhat you gave me was good, however it refused to load the data table, checked ALL files for spelling etc and now it works.but with this it still refuses to sort :)

	<tr>	  <xsl:call-template name="th">		<xsl:with-param name="header">artist</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">album</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">source</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">kind</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">added</xsl:with-param>	  </xsl:call-template>	</tr>	<xsl:choose><!--artist-->		<xsl:when test="$sortBy = 'artist' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="artist" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'artist' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="artist" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--album-->		<xsl:when test="$sortBy = 'album' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="album" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'album' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="album" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--source-->		<xsl:when test="$sortBy = 'source' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="source" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'source' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="source" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--kind-->		<xsl:when test="$sortBy = 'kind' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="kind" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'kind' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="kind" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--added-->		<xsl:when test="$sortBy = 'added' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'added' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="ascending" />			</xsl:apply-templates>		</xsl:when>	</xsl:choose>	</table>	</div>	</div>  </body>  </html></xsl:template><xsl:template match="music">	<tr>	  <td><xsl:value-of select="artist"/></td>	  <td><xsl:value-of select="album"/></td>	  <td><xsl:value-of select="source"/></td>	  <td><xsl:value-of select="kind"/></td>	  <td><xsl:value-of select="added"/></td>	</tr></xsl:template><xsl:template name="th">  <xsl:param name="header"/>  <th>	<a>	  <xsl:attribute name="href">?sortBy=<xsl:value-of select="$header"/>&sortOrder=<xsl:choose>		  <xsl:when test="$sortOrder = 'descending'">ascending</xsl:when>		  <xsl:when test="$sortOrder = 'ascending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="$header"/>	</a>  </th></xsl:template>

i cant really see anything thats wrong in that, then again i am only an xslt uber junior hehe

Link to post
Share on other sites

Are you sure your whitelist in stylesheet.php is corrected from the spelling mistake too? The parameter doesn't seem to get passed, but it's rather reseted to the default value.What is the complete source code of stylesheet.php now?

Link to post
Share on other sites

yeah as far as i can see its all correct spelling &amp and case wise.here are the 3files anywaysstylesheet.php

<?php//This file will always return an XSLT stylesheet, so we specify that with this MIME typeheader('Content-type: application/xslt+xml');/*If any of the two parameters gets a value that is not whitelisted (in the first argument of the ereg()), the default value will be used */$sortBy = (!ereg('added',$_GET['sortBy']) ? 'added' : $_GET['sortBy']);$sortOrder = (!ereg('descending|ascending',$_GET['sortOrder']) ? 'descending' : $_GET['sortOrder']);//Load the XSLT stylesheet$dom = new DOMDocument;$dom->load('library.xsl');//Get all parameters$params = $dom->documentElement->getElementsByTagNameNS('http://www.w3.org/1999/XSL/Transform','param');//Loop thru all parametersfor ($i = 0; $i < $params->length; $i++) {	$param = $params->item($i);	/* Treat specially the ones we know and adjust their value to the filtered variant above */	switch($param->getAttribute('name')) {	case 'sortBy':		$param->nodeValue = $sortBy;		break 2;	case 'sortOrder':		$param->nodeValue = $sortOrder;		break 2;	default:		break 2;	}}//Return the stylesheet to the browserecho $dom->saveXML();?>

library.php

<?php//This file will always return an XSLT stylesheet, so we specify that with this MIME typeheader('Content-type: application/xslt+xml');/*If any of the two parameters gets a value that is not whitelisted (in the first argument of the ereg()), the default value will be used */$sortBy = (!ereg('added',$_GET['sortBy']) ? 'added' : $_GET['sortBy']);$sortOrder = (!ereg('descending|ascending',$_GET['sortOrder']) ? 'descending' : $_GET['sortOrder']);//Load the XSLT stylesheet$dom = new DOMDocument;$dom->load('library.xsl');//Get all parameters$params = $dom->documentElement->getElementsByTagNameNS('http://www.w3.org/1999/XSL/Transform','param');//Loop thru all parametersfor ($i = 0; $i < $params->length; $i++) {	$param = $params->item($i);	/* Treat specially the ones we know and adjust their value to the filtered variant above */	switch($param->getAttribute('name')) {	case 'sortBy':		$param->nodeValue = $sortBy;		break 2;	case 'sortOrder':		$param->nodeValue = $sortOrder;		break 2;	default:		break 2;	}}//Return the stylesheet to the browserecho $dom->saveXML();?>

library.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="sortBy">added</xsl:param><xsl:param name="sortOrder">descending</xsl:param><xsl:template match="/library">  <html>  <link href="library.css" rel="stylesheet" type="text/css" />  <title>acousticmushroom.com .::. music . . .</title><body>	<div id="page">	<div id="header" onclick="location.href='http://www.acousticmushroom.com/blog/';" style="cursor: pointer;"/>	   <div id="content">		<h5>		<xsl:for-each select="/library/stats">			Xander's Music Collection<br/><xsl:value-of select="updated"/>		   </xsl:for-each>		</h5>		<h6>		<xsl:for-each select="/library/stats">			<p>			artists - <xsl:value-of select="artists"/> . . .			albums - <xsl:value-of select="albums"/> . . .			songs - <xsl:value-of select="songs"/></p>			<p><xsl:value-of select="playback"/></p>			<p><xsl:value-of select="size"/></p>			<p>mp3 albums - <xsl:value-of select="mp3"/> . . .			aac albums - <xsl:value-of select="aac"/> . . .			lossless albums - <xsl:value-of select="lossless"/></p>		  			</xsl:for-each>			<p>please note all dates showing 2007-08-01 are albums added to the library prior to the website, ie. i do not have a date for them... yet</p>		<p>to search the library use your browsers find function (CTRL+F)</p>		<p>		click <a href="http://www.acousticmushroom.com/blog">here</a> to return home</p>		<p>   <a href="http://www.acousticmushroom.com/assets/files/library.pdf">pdf version</a> </p>		</h6>	<table>	<tr>	  <xsl:call-template name="th">		<xsl:with-param name="header">artist</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">album</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">source</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">kind</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">added</xsl:with-param>	  </xsl:call-template>	</tr>	<xsl:choose><!--artist-->		<xsl:when test="$sortBy = 'artist'">			<xsl:apply-templates select="music">				<xsl:sort select="artist" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--album-->		<xsl:when test="$sortBy = 'album'">			<xsl:apply-templates select="music">				<xsl:sort select="album" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--source-->		<xsl:when test="$sortBy = 'source'">			<xsl:apply-templates select="music">				<xsl:sort select="source" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--kind-->		<xsl:when test="$sortBy = 'kind'">			<xsl:apply-templates select="music">				<xsl:sort select="kind" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--added-->		<xsl:when test="$sortBy = 'added'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="descending" />			</xsl:apply-templates>		</xsl:when>	</xsl:choose>	</table>	</div>	</div>  </body>  </html></xsl:template><xsl:template match="music">	<tr>	  <td><xsl:value-of select="artist"/></td>	  <td><xsl:value-of select="album"/></td>	  <td><xsl:value-of select="source"/></td>	  <td><xsl:value-of select="kind"/></td>	  <td><xsl:value-of select="added"/></td>	</tr></xsl:template><xsl:template name="th">  <xsl:param name="header"/>  <th>	<a>	  <xsl:attribute name="href">?sortBy=<xsl:value-of select="$header"/>&sortOrder=<xsl:choose>		  <xsl:when test="$sortOrder = 'descending'">ascending</xsl:when>		  <xsl:when test="$sortOrder = 'ascending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="$header"/>	</a>  </th></xsl:template></xsl:stylesheet>

cheers :)

Link to post
Share on other sites

OK. The only thing I can think of to be wrong is that nodeValue is not adjusting the node value (despite the fact they say it's not read only).In the stylesheet, reduce the parameters to:

<xsl:param name="sortBy"/><xsl:param name="sortOrder"/>

And try again. The PHP should give them a default value anyway. If it doesn't, I'll try to look for an alternative way.[edit]Here's a possible alternative:replace

	case 'sortBy':		$param->nodeValue = $sortBy;		break 2;	case 'sortOrder':		$param->nodeValue = $sortOrder;		break 2;

with

	case 'sortBy':		$param->appendChild(new DOMText($sortBy));		break 2;	case 'sortOrder':		$param->appendChild(new DOMText($sortOrder));		break 2;

[/edit]

Link to post
Share on other sites

changing

<xsl:param name="sortBy" select="'added'"/><xsl:param name="sortOrder" select="'descending'"/>

to

<xsl:param name="sortBy"/><xsl:param name="sortOrder"/>

removed the suffix at the end of the url fromlibrary.php?sortBy=added&sortOrder=descendingtolibrary.php?sortBy=added&sortOrder=and changing the stylesheet.php also did nothing....

Link to post
Share on other sites

I think I know the reason. Try to make

break 2;

to just

break;

I used break 2; as a performance booster, because once done, it would go loop over the next parameter without looking what's after the switch(). I may have accidently gone over the for() though.

Link to post
Share on other sites

There's YOUR error (finally not an error of mine :) )! You haven't descibed all possible situations. Look:

	<xsl:choose><!--artist-->		<xsl:when test="$sortBy = 'artist'">			<xsl:apply-templates select="music">				<xsl:sort select="artist" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--album-->		<xsl:when test="$sortBy = 'album'">			<xsl:apply-templates select="music">				<xsl:sort select="album" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--source-->		<xsl:when test="$sortBy = 'source'">			<xsl:apply-templates select="music">				<xsl:sort select="source" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--kind-->		<xsl:when test="$sortBy = 'kind'">			<xsl:apply-templates select="music">				<xsl:sort select="kind" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--added-->		<xsl:when test="$sortBy = 'added'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="descending" />			</xsl:apply-templates>		</xsl:when>	</xsl:choose>

This must contain both the cases with ascending and descending like your previous implementation:

	<xsl:choose><!--artist-->		<xsl:when test="$sortBy = 'artist' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="artist" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'artist' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="artist" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--album-->		<xsl:when test="$sortBy = 'album' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="album" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'album' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="album" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--source-->		<xsl:when test="$sortBy = 'source' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="source" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'source' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="source" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--kind-->		<xsl:when test="$sortBy = 'kind' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="kind" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'kind' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="kind" order="ascending" />			</xsl:apply-templates>		</xsl:when><!--added-->		<xsl:when test="$sortBy = 'added' and $sortOrder = 'descending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="descending" />			</xsl:apply-templates>		</xsl:when>		<xsl:when test="$sortBy = 'added' and $sortOrder = 'ascending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="ascending" />			</xsl:apply-templates>		</xsl:when>	</xsl:choose>

Link to post
Share on other sites

tried the edit you gave, still not sorting, i might use a different approach, the links in the headers.... if i was to say link it to another page (source.php) what would i use?? im guessing it would go here?

	<tr>	  <xsl:call-template name="th">		<xsl:with-param name="header">artist</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">album</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">source</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">kind</xsl:with-param>	  </xsl:call-template>	  <xsl:call-template name="th">		<xsl:with-param name="header">added</xsl:with-param>	  </xsl:call-template>	</tr>

Link to post
Share on other sites

It IS sorting! By "added" at least. I've noticed you haven't whitelisted the rest of the gang in the following line from stylesheet.php:

$sortBy = (!ereg('added',$_GET['sortBy']) ? 'added' : $_GET['sortBy']);

You need to add the rest too, making it more like:

$sortBy = (!ereg('artist|album|source|kind|added',$_GET['sortBy']) ? 'added' : $_GET['sortBy']);

Link to post
Share on other sites

OMG that worked a treat!!!!!!!!!!! haha sorry i think im still drunk, my footy team won last nite and were in the finals, the match b4 the grand final!!!haha i dunno why i told you that but anyways! ?(like i said im still drunk)ok, the only thing now is its only sorting descending. when i click the link it doesnt switch, even tho the url says ascending its sorting descendinghmmm....im guessing its this?

	  <xsl:attribute name="href">?sortBy=<xsl:value-of select="$header"/>&sortOrder=<xsl:choose>		  <xsl:when test="$sortOrder = 'descending'">ascending</xsl:when>		  <xsl:when test="$sortOrder = 'ascending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>

Link to post
Share on other sites

Go and get some sleep. You're still very drunk :) . I checked all columns in both orders and it is sorting properly everything everywhere as it should.

Link to post
Share on other sites

That's just a guess, but I think the problem is with the & in the URL of the PI. It seems Firefox doesn't send anything after it. Either that, or it treats it literally, meaning PHP receives the variables "sortBy" and "amp;sortOrder" rather then just "sortOrder. I'm clueless as to how this could be solved right now. I'll try to play with it on my own and let you know.But this works in IE and Opera too. It's a Firefox problem really.

Link to post
Share on other sites

ok i would like to thank you soo much for your help...i have taken a different approach, wich works fine for me reallythen main thing i wanted was to have one xml file, and i dojust have different php's and xsl's coz that content doesnt change, its just the xml...if you want to get the way you made up working please feel free, and let me know when you do..here is a little shout out to yourself on my site http://www.acousticmushroom.com/blog/if you ever do get the other way working in firefox, please let me know!!! you can post a comment on my site if u wish!cheers mate, have a good one!

Link to post
Share on other sites

Heh. Thanks for the appreciation :) .OK. Here's a thought about that one. Replace

$sortBy = (!ereg('added',$_GET['sortBy']) ? 'added' : $_GET['sortBy']);$sortOrder = (!ereg('descending|ascending',$_GET['sortOrder']) ? 'descending' : $_GET['sortOrder']);

with

$usedGET['sortBy'] = (isset($_GET['amp;sortBy']) ? $_GET['amp;sortBy'] : $_GET['sortBy']);$usedGET['sortOrder'] = (isset($_GET['amp;sortOrder']) ? $_GET['amp;sortOrder'] : $_GET['sortOrder']);$sortBy = (!ereg('added',$usedGET['sortBy']) ? 'added' : $usedGET['sortBy']);$sortOrder = (!ereg('descending|ascending',$usedGET['sortOrder']) ? 'descending' : $usedGET['sortOrder']);

I believe firefox sends amp;sortOrder while other browsers send just sortOrder, so what I'm doing here is to detect whether the browser sends that and use it if it is sent. If not, use the proper variant. Then, we filter the filtered variable. I've filtered both variables just for ensurance and integrity, but technically speaking, sortBy could be removed.If that doesn't work, I don't think I'll ever think of a good solution for this.... unless you were able to configure your php.ini to treat ";" as a separation character (as is by default in php.ini-reccomended btw).

Link to post
Share on other sites

yeah tried that, it sorted ascending for artist, then when i clicked it again it changed back to its default....but mate... i think you have done more than enough!! i have achieved what i wanted, having one xml doc load dynamically into several different style sheets using php!and using dreamweaver if i need to replace anything in the xslt files i just use find replace in current local folder :) works an absolute treat! hehethanks again mate!leave a comment on my blog page if u wish :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...