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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting by element value - XSL

Status
Not open for further replies.

andyros

Programmer
Jul 12, 2005
42
GB
Hi guys

I posted last week about splitting data up into sevral pages and got a great response that i should create divs for each page and show / hide them via hyperlinks.

Well i've got a new problem :) I've applied this technique to sorting by creating more divs which display content in a sorted manner.

The problem i am having is this:

Code:
<query>

  <result>
     <title>example</doctitle>
     <location>c:\somewhere</location>
     <category>Books</category>
  </result>

  <result>
     <title>example</doctitle>
     <location>c:\somewhere</location>
     <category>Cars</category>
  </result>

  <result>
     <title>example</doctitle>
     <location>c:\somewhere</location>
     <category>Books</category>
  </result>

</query>

As you can see each result has a category. I've created a div to sort the results by the category value. But i would like to only show results from certain categories.

So i would have a link for books and a link for cars, when books is clicked it shows only results where category value is books etc.

I've tried:

<xsl:sort select="category/@Books"/>

but this doesnt seem to work [ponder]

Any ideas?

thanks
andy
 
ok is this close?

Code:
<xsl:template match="query" mode="divs">

  <div id="sortedPage{position()}" style="display: none;">
	<xsl:apply-templates select="result">
		[b]<xsl:sort select="//result[@category='business']"/>[/b]
	</xsl:apply-templates>
  </div>

</xsl:template>

I've changed the result element of the XML to

Code:
<result category="Books">

and scraped the category node inside result.

It creates the div ok but the there is something wrong with the sort statement...it doesnt work!! It just displays all results with no filtering.
 
i've just realised you cannot use xpath expressions inside xsl sort as it doesnt accept it! :(

any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top