Jump to content

XInclude


xander85

Recommended Posts

this was in a previous topic i started, thought i would start it fresh, im not having luck in the Query2XML part atm, so for a temp solution i thought id use this...I recently upgraded the server to PHP5 so im hoping this will now work.From what the previous topic had, im guessing i need the following filesinclude.php

<?php//View the result as an XML fileheader('Content-type: application/xml');//Initiate the DOMDocument class$dom = new DOMDocument;//Load library-album.xml$dom->load('library-date.xml');//Perform XIncludes$dom->xinclude();//View the result$dom->saveXML();?>

does somthing go in the () parts in the following?

//Perform XIncludes$dom->xinclude();//View the result$dom->saveXML();
library-date.xml
<?xml version='1.0'?><?xml-stylesheet type="text/xsl" href="library-album.xsl"?><library xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include href="XML.xml"/></library>

xml.xml

<?xml version="1.0" encoding="utf-8" ?>  <!-- Table music -->	<music>		<ID>1</ID>		<artist>oasis</artist>		<album>(what's the story) morning glory?</album>		<source>ash</source>		<kind>aac audio</kind>		<added>2007-08-01</added>	</music>  <!-- Table stats -->	<stats>		<ID>1</ID>		<artists>1,670</artists>		<albums>1,853</albums>		<songs>23,945</songs>		<updated>2007-08-25</updated>		<size>129.41</size>		<playback>65 days, 07 hours, 49 minutes & 24 seconds</playback>		<mp3>1,287</mp3>		<aac>420</aac>		<lossless>0</lossless>	</stats>

i tried to play around, trial and error but failed. like most things im trying to do on here :) here is what i got as an errorhttp://www.acousticmushroom.com/library/test/include.phponce again thanks in advance, i know ive been buggin ya all for a while. once i have somtin thats at least semi-automated i'll be happy :)cheers

Link to comment
Share on other sites

XIncludes are not like normal includes. They require that both the included document and the document that includes it are well formed XML documents.Your included XML has two root elements (<music/> and <stats/>). Either separate that into two XMLs with those as root elements and include them both, or add a single element around them.

Link to comment
Share on other sites

ok still not working.. :)here is exactly what i have now, including the suggestion you made.. i renamed a few of the files to for testing purposes.hehe your probably sick of me by nowfile - library.php - http://www.acousticmushroom.com/library/test/library.php

<?php//View the result as an XML fileheader('Content-type: application/xml');//Initiate the DOMDocument class$dom = new DOMDocument;//Load library.xml$dom->load('library.xml');//Perform XIncludes$dom->xinclude();//View the result$dom->saveXML();?>

file - library.xml - http://www.acousticmushroom.com/library/test/library.xml

<?xml version='1.0'?><?xml-stylesheet type="text/xsl" href="library-date.xsl"?><library xmlns:xi="http://www.w3.org/2001/XInclude">	<xi:include href="music.xml"/>	<xi:include href="stats.xml"/></library>

file - music.xml - http://www.acousticmushroom.com/library/test/music.xml

	<music>		<ID>1</ID>		<artist>oasis</artist>		<album>(what's the story) morning glory?</album>		<source>ash</source>		<kind>aac audio</kind>		<added>2007-08-01</added>	</music>	<music>		<ID>2</ID>		<artist>dmx</artist>		<album>...and then there was x</album>		<source>ash</source>		<kind>aac audio</kind>		<added>2007-08-01</added>	</music>

file - stats.xml - http://www.acousticmushroom.com/library/test/stats.xml

	<stats>		<ID>1</ID>		<artists>1,670</artists>		<albums>1,853</albums>		<songs>23,945</songs>		<updated>2007-08-25</updated>		<size>129.41</size>		<playback>65 days, 07 hours, 49 minutes & 24 seconds</playback>		<mp3>1,287</mp3>		<aac>420</aac>		<lossless>0</lossless>	</stats>

and of course library.xsl for the XMLhttp://www.acousticmushroom.com/library/test/library.xsland then library.css to display everyting nice and neathttp://www.acousticmushroom.com/library/test/library.cssthe resulting product should look like thishttp://www.acousticmushroom.com/library/library-date.xml

Link to comment
Share on other sites

OK, dude, seriously. You need to remember this simple rule: XML documents allow only one root element. Look at music.xml again, and tell me how many root elements you see. I see two <music/> elements at the root level.

Link to comment
Share on other sites

i really do appreciate your help, as i am new to this im finding it a little hard to follow, it does seem pretty simple.here are the orginal files i want to include into the one. i want to do this to make editing and updating easy.http://www.acousticmushroom.com/library/test/music.xmlhttp://www.acousticmushroom.com/library/test/stats.xmlas you can probably recall i had 3 files for my site, all with the same XML but different style sheets to sort it differently (if there is an easy way please tell me)all i want to do is load them into one xml doc, library.xmland i can copy that load code into other files so i can attach different style sheets etc.i must have something close to working from what you have given me previously?

Link to comment
Share on other sites

Well, those two files you give as link + the library.xml from above should be included normally.However, what it seems you want may require a totally different approach. What would you say of a single XML file (with or without all of those inclusions, it doesn't matter), but with adjusted processing instruction depending on the required stylesheet? If only sorting is the difference, you may not even need two stylesheets.Actually, if you have the PHP XSL extension, this is going to be even more of a breeze, as you can do the transformation on the server, and just set parameters in the PHP file depending on, say, a GET parameter passed...Wait, wait (I'm about to make a revolution here!!!)... you can do it even without the XSL extension. I know how!First, and by far the most important, you'll need to rework your stylesheet to use parameters and switch sorting depending on them. Here's what I believe is a good start (reworked from the stylesheet you gave):

<?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="'Added'"/><xsl:param name="sortOrder" select="'descending'"/><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>sort by<br/>		<a href="library-album.xml">album</a>, 		<a href="library-artist.xml">artist</a>, 		<a href="library-date.xml">date added</a>, 		<a href="http://www.acousticmushroom.com/assets/files/library.pdf">pdf version</a>		</p>		</h6>	<table>	<tr>	  <th>Artist</th>	  <th>Album</th>	  <th>Source</th>	  <th>Kind</th>	  <th>Added</th>	</tr>	<xsl:choose>		<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 = 'accending'>			<xsl:apply-templates select="music">				<xsl:sort select="Added" order="accending" />			</xsl:apply-templates>		</xsl:when>	</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:stylesheet>

Some additional adjustments would have to be made if you want clickable links on the tables for the different sortings.After that, you'll dynamically load a stylesheet and adjust it's parameters. For that, create a PHP page, say stylesheet.php with the following contents:

<?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|accending',$_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 browser$dom->saveXML();?>

And do a similar thing for the XML file (which should look like your library-date.xml), but adjust the href of the xml-stylesheet PI instead. Let's say we call that "library.php":

<?php//This file will always return an XML document, so we specify that with this MIME typeheader('Content-type: application/xml');//Load the XML file$dom = new DOMDocument;$dom->load('library.xml');//The first child node of the XML is assumed to be the PI we need to adjust$dom->firstChild->data = 'type="text/xsl" href="stylesheet.php?sortBy=' . $_GET['sortBy'] . '&sortOrder=' . $_GET['sortOrder'] . '"';//Display the result$dom->saveXML();?>

Now a link to library.php should result in your current code and a link to library.php?sortOrder=accending will adjust the sorting order to accending. Inspect the two pairs of source codes you're getting to see my point if you don't already.Now,

Link to comment
Share on other sites

However, what it seems you want may require a totally different approach. What would you say of a single XML file (with or without all of those inclusions, it doesn't matter), but with adjusted processing instruction depending on the required stylesheet? If only sorting is the difference, you may not even need two stylesheets.
THIS IS EXACTLY WHAT I WANT TO DO hahahits the same data, just sorted by artist/album/source/kind/date prefferably with links to sort in the table headers! :)ok just to claify, lets start from the beginningi will need (from what you have here) 4 fileslibrary.xsl for the style sheetlibrary.xml for the XML datastylesheet.php for loading the different style sheetslibrary.php - wich im guessing is the url you open to view the page?i will create the files based on your example, as i know little about all 3 of those file types, it would be very helpful if you could explain how it works.cheers
Link to comment
Share on other sites

THIS IS EXACTLY WHAT I WANT TO DO hahahits the same data, just sorted by artist/album/source/kind/date prefferably with links to sort in the table headers! :)
OK. So in the end, we're going to make some more modifications to the stylesheet, but let's keep it as is for now.
ok just to claify, lets start from the beginningi will need (from what you have here) 4 fileslibrary.xsl for the style sheetlibrary.xml for the XML datastylesheet.php for loading the different style sheetslibrary.php - wich im guessing is the url you open to view the page?
Exactly.
i will create the files based on your example, as i know little about all 3 of those file types, it would be very helpful if you could explain how it works.cheers
I've left comments in the PHP files to let you know what they do.The overall process is as follows:
  1. You request library.php with or without some query strings parameters that are needed to select a different stylesheet in the PI.
  2. library.php loads your XML file and uses stylesheet.php as a stylesheet. The query strings for stylesheet.php are practically "copied" from the ones library.php gets.
  3. The browser gets an XML file that needs to be processed with stylesheet.php as XSLT stylesheet.
  4. The browser makes a new request for the XSLT file at stylesheet.php as specified in the resulting XML file.
  5. The stylesheet.php file first loads your XSLT file and then, based on the query string variables, it modifies the value of the two <xsl:param/> elements at the top of the stylesheet.
  6. The browser gets the resulting XSLT stylesheet after those modifications.
  7. Since there are some conditions in the XSLT file, you'll get a different sorting based on the value of the parameter. The value of the parameter is determined by what was passed to stylesheet.php which in practice is determined by what was passed to library.php.

Link to comment
Share on other sites

ive made all the files, changed a few things to make it work some of the modified data in the xml, but im still not sure what i have to do to make it sort?atm i cant even get it to display it in the browser.... all the files are here http://www.acousticmushroom.com/testdo i need a different library.php file for each way i sort it? is it as simple as making clickable links in the headers of the table? if so how? i know im being a pain... sorry :)

Link to comment
Share on other sites

ive made all the files, changed a few things to make it work some of the modified data in the xml, but im still not sure what i have to do to make it sort?atm i cant even get it to display it in the browser.... all the files are here http://www.acousticmushroom.com/testdo i need a different library.php file for each way i sort it? is it as simple as making clickable links in the headers of the table? if so how? i know im being a pain... sorry :)
Oops. My bad. Sorry. I always forget to echo $dom. Replace the lines
$dom->saveXML();

with

echo $dom->saveXML();

in both library.php and stylesheet.php.

Link to comment
Share on other sites

ah awsome, it loaded the xml, but only the raw xmldo i need this at the top of the library.xml file??
<?xml-stylesheet type="text/xsl" href="library.xsl"?>

i just tried it and it got an error, im guessing there is something wrong wid the stylesheet.php?
Link to comment
Share on other sites

I have a typo in the XSLT.Replace

		<xsl:when test="$sortBy = 'Added' and $sortOrder = 'accending'>

with

		<xsl:when test="$sortBy = 'Added' and $sortOrder = 'accending'">

(note the quote in the end from the second)If you want, check out the XML with this XSLT without PHP to ensure there aren't any other typos.And yes, the way library.php is made, you must have a PI for the stylesheet and it must be the first and only one in library.xml. If you really want to remove it, replace

$dom->firstChild->data = 'type="text/xsl" href="stylesheet.php?sortBy=' . $_GET['sortBy'] . '&sortOrder=' . $_GET['sortOrder'] . '"';

with

$dom->insertBefore($dom->createProcessingInstruction('xml-stylesheet','type="text/xsl" href="stylesheet.php?sortBy=' . $_GET['sortBy'] . '&sortOrder=' . $_GET['sortOrder'] . '"'),$dom->documentElement);

That way, a new PI will be inserted when the PHP file is requested. Note that it will be inserted right before the root element (which in turns means it will be the last PI).Also, it's normal that you receive the XML file. That's how this works. You're suppose to get an XML file and the XSLT processing is done on the client. If you want to do it on the server, you'll have to somehow enable the XSL extension.

Link to comment
Share on other sites

mad!! everything is loading perfectly, there was a </xsl:choose> missing in the xsl file, wich was the parsing error i was getting, fixed that and now its all loading fine.now to FINISH HIM! how do i add links to the table headers to sort by that colum (artist/album/source/kind/date) and to do it in both ascending and descending, once thats done its perfect. all i have to do is change the library.xml file when i update it. copy and paste is all i have to do for that one!!!i cant thank you enough, you have been an absolute champ!!! *applause* :)here is the libray.xsl file code (im guessing the sorting links will go here somewhere?

<?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="'added'"/><xsl:param name="sortOrder" select="'descending'"/><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>	  <th>Artist</th>	  <th>Album</th>	  <th>Source</th>	  <th>Kind</th>	  <th>Added</th>	</tr>	<xsl:choose>		<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 = 'accending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="accending" />			</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:stylesheet>

Link to comment
Share on other sites

	   <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>

i also noticed that the code above is not showing ie the stats etc, you can see them here -> http://acousticmushroom.com/library/library-date.xml
Link to comment
Share on other sites

i also noticed that the code above is not showing ie the stats etc, you can see them here -> http://acousticmushroom.com/library/library-date.xml
SCRAP THAT haha!fixed it, i should look harder at the code before i make a post haha, sorry bout thatthe
<xsl:for-each select="library/stats">

was missing the / before library, replaced with

<xsl:for-each select="/library/stats">

Link to comment
Share on other sites

It doesn't seem to be (completely) working for me though. I see the XML with the PI, but not the result for some reason.And I think I know why is that. In library.php, replace the

&sortOrder

with

&sortOrder

Oddly enough, I thought that DOMDocument::createProcessingInstruction() would automatically escape entitities. Perhaps I was wrong. Still, it renders fine in Firefox though, so while opening a can of worms, I really wonder which browser is in error. I'll investigate this further...As for creating the links. There are a few ways to do it, but here's what I think is the best (or at least the best I think of from the top of my head).First, replace

	<tr>	  <th>Artist</th>	  <th>Album</th>	  <th>Source</th>	  <th>Kind</th>	  <th>Added</th>	</tr>

with

	<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>

And add the following 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'">accending</xsl:when>		  <xsl:when test="$sortOrder = 'accending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="header"/>	</a>  </th></xsl:template>

This will create a link inside each table header that will always sort in the order which is reversed from the current and by the column clicked. There is probably a way to force sortOrder to be descending or accending by default unless you were already sorting by the same header and in the same order, but I feel too lazy now to do it. Still, this should be a good start, giving you a pretty interactive table even in this fashion.

Link to comment
Share on other sites

im not exaclty sure where this template goes in the document??

<xsl:template name="th">

does it replace this sorting sting?

	<xsl:choose>		<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 = 'accending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="accending" />			</xsl:apply-templates>		</xsl:when>	</xsl:choose>

ive tried different parts of the file but cannot get it to work... also it still will not load in ie... even after i changed this

&sortOrder

here is the current version of the xslt file

<?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="'added'"/><xsl:param name="sortOrder" select="'descending'"/><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>	  <th>Artist</th>	  <th>Album</th>	  <th>Source</th>	  <th>Kind</th>	  <th>Added</th>	</tr>	<xsl:choose>		<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 = 'accending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="accending" />			</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:stylesheet>

do you need to merge<tr><th>Artist....... blah blah etc</th></tr> and<xsl:template blah blah etc />together so it loads the links and adds the sort string?

Link to comment
Share on other sites

The only place <xsl:template/> can go is as a direct child of <xsl:stylesheet/>. So, when someone tells you to add a template, it means you'll put it somewhere in the stylesheet, but on the appropriate level, without replacing existing templates. For example, right after your last template, replacing:

</xsl:template></xsl:stylesheet>

with

</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'">accending</xsl:when>		  <xsl:when test="$sortOrder = 'accending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="header"/>	</a>  </th></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

almost there, almost......i added in the code as u mentioned, but its not displaying the table headers? i noticed a typo?? maybe im wrong im not surethe sort...... didnt have a $ as a prefix, it wouldnt load, had a xsl transorm error in firefox, i changed it to $sortOrder and $sortByand it loaded in firefox just fine, but missing the table headers :)

<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'">accending</xsl:when>		  <xsl:when test="$sortOrder = 'accending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="header"/>	</a>  </th></xsl:template>

unfortunatly it still refuses to load in iexplore... haha, kinda sux when you make somthing that works in one browser but not the other, im guessing older versions of iexplore dont have the correct xsl processors installed like ff and safari dooo? thats just a HUGE guess haha.....so yeah here is the source folder again incase you cbf scrolling the page to find it again hehe.http://www.acousticmushroom.com/test/

Link to comment
Share on other sites

almost there, almost......i added in the code as u mentioned, but its not displaying the table headers? i noticed a typo?? maybe im wrong im not surethe sort...... didnt have a $ as a prefix, it wouldnt load, had a xsl transorm error in firefox, i changed it to $sortOrder and $sortByand it loaded in firefox just fine, but missing the table headers :)
<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'">accending</xsl:when>		  <xsl:when test="$sortOrder = 'accending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="header"/>	</a>  </th></xsl:template>

unfortunatly it still refuses to load in iexplore... haha, kinda sux when you make somthing that works in one browser but not the other, im guessing older versions of iexplore dont have the correct xsl processors installed like ff and safari dooo? thats just a HUGE guess haha.....so yeah here is the source folder again incase you cbf scrolling the page to find it again hehe.http://www.acousticmushroom.com/test/

Yes. I missed the $ in the value-of. I also noticed that the entity has to be encoded (again with the &), making the code:
<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'">accending</xsl:when>		  <xsl:when test="$sortOrder = 'accending'">descending</xsl:when>		</xsl:choose>	  </xsl:attribute>	  <xsl:value-of select="$header"/>	</a>  </th></xsl:template>

Link to comment
Share on other sites

headers are now showing, but it still only sorts by 'added' there must me somtin thats overwriting the "onclick" sorting
Look at this part:
	<xsl:choose>		<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 = 'accending'">			<xsl:apply-templates select="music">				<xsl:sort select="added" order="accending" />			</xsl:apply-templates>		</xsl:when>	</xsl:choose>

This is where all "handlers" for the different value combinations are. Currently, there are only handlers for the "added" column in accending and descending order. Fill out the rest needed <xsl:when/>s and you'll have complete sorting capabilities.Oh, and according to IE, it's spelled "ascending" (this was perhaps my error, but I was hoping you'll notice it). Also, notice that "added" and "Added" are treated differently. Select a case you'll use and use it everywhere. Replace the occurances of the other.

Link to comment
Share on other sites

added this

	<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>

changed accending, to ascending. chose lower case, as its the same as the xml file, and it looks better hehe.however still not sorting, the URL in the address bar of FF changes from the default oflibrary.php?sortBy=added&sortOrder=ascendingto say when the header is clickedlibrary.php?sortBy=artist&sortOrder=ascendingbut the sorting still remains.also its not switching from ascending to descending and vise versaive checked all the files for spelling and case and & but it still refuses to load in IE :)

Link to comment
Share on other sites

When you refresh the page in IE, you'll see an error. Next time, see what the error is please (and if you think you know what causes it, don't be shy to try).It seems IE doesn't like that we have both a select attribute and non-empty content on the parameters. Oh well, replace

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

with

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

Don't forget to change it to "ascending" everywhere in the two PHPs as well. Not to mention to add the rest of the gang there too.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...