Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 29th, 2013, 05:02 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default sorting with XSLT

Dear All,

I need sort the following xml document netted ul nodes each contain id attribute for year, followed by month , day and title.

xml document

<?xml version="1.0" ?>
<div class="css-treeview">
<ul id="2007">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">2008</label>
<ul id="2">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">2</label>
<ul id="23">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">23</label>
<ul id="Open Office">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML - Copy">Office Open XML - Copy</a>
</label>
</li>
</ul>
<ul id="Oxford XML">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="1842eab3" onclick="doContentLoad(this,'1842eab3_Office_Open_ XML/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML">Office Open XML</a>
</label>
</li>
</ul>
<ul id="Office XML">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML - Copy">Office Open XML - Copy</a>
</label>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul id="10">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">10</label>
<ul id="23">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">23</label>
<ul id="Open Office">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML - Copy">Office Open XML - Copy</a>
</label>
</li>
</ul>
</li>
</ul>
<ul id="2">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="1842eab3" onclick="doContentLoad(this,'1842eab3_Office_Open_ XML/topics/1_Front_Matter/topic.htm', '1', '1')" title="2">2</a>
</label>
<ul id="Oxford XML">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="1842eab3" onclick="doContentLoad(this,'1842eab3_Office_Open_ XML/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML">Office Open XML</a>
</label>
</li>
</ul>
<ul id="Office XML">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML - Copy">Office Open XML - Copy</a>
</label>
</li>
</ul>
</li>
</ul>
<ul id="10">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="1842eab3" onclick="doContentLoad(this,'1842eab3_Office_Open_ XML/topics/1_Front_Matter/topic.htm', '1', '1')" title="10">10</a>
</label>
<ul id="Office XML">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="Office Open XML - Copy">Office Open XML - Copy</a>
</label>
<ul>
<li>
<a class="lnkTopic" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="Front Matter">Front Matter</a>
</li>
<li>
<a class="lnkTopic" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/2_Table_of_Contents/topic.htm', '1', '1')" title="Table of Contents">Table of Contents</a>
</li>
<li>
<a class="lnkTopic" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/topics/3_Scope/topic.htm', '1', '1')" title=" Scope"> Scope</a>
</li>
<li>
<a class="lnkTopic" data-pid="e10ab2ab" onclick="doContentLoad(this,'e10ab2ab_Office_Open_ XML_-_Copy/pdf/Office Open XML - Copy.pdf', '1', '1')" title="Office Open XML - Copy (pdf)">Office Open XML - Copy (pdf)</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul id="2010">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">2007</label>
<ul id="8">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">8</label>
<ul id="20">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">20</label>
<ul id="2c507bbd">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="2c507bbd" onclick="doContentLoad(this,'2c507bbd_Project_cons ult_newsletter_en/topics/1_Front_Matter/topic.htm', '1', '1')" title="Project consult newsletter en">Project consult newsletter en</a>
</label>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul id="7">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">7</label>
<ul id="14">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0" class="taxonomy">14</label>
<ul id="c5e6eb7e">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="c5e6eb7e" onclick="doContentLoad(this,'c5e6eb7e_SharePointSe rver2007_ProductGuide_-_Copy/topics/1_Front_Matter/topic.htm', '1', '1')" title="SharePointServer2007 ProductGuide - Copy">SharePointServer2007 ProductGuide - Copy</a>
</label>
</li>
</ul>

<ul id="1483f916">
<li>
<input type="checkbox" id="item-0" />
<label for="item-0">
<a class="lnkPub" data-pid="1483f916" onclick="doContentLoad(this,'1483f916_SharePointSe rver2007_ProductGuide/topics/1_Front_Matter/topic.htm', '1', '1')" title="SharePointServer2007 ProductGuide">SharePointServer2007 ProductGuide</a>
</label>
</li>
</ul>

</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>





my xslt is as follows

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="*|@*|text()">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()" />
</xsl:copy>
</xsl:template>

<xsl:template match="div">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()">
<xsl:sort select="@id" order="descending" data-type="number"/>

</xsl:apply-templates>

</xsl:copy>
</xsl:template>

<xsl:template match="div/ul/li">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()">
<xsl:sort select="@id" order="descending" data-type="number"/>

</xsl:apply-templates>

</xsl:copy>
</xsl:template>

<xsl:template match="div/ul/li/ul/li">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()">
<xsl:sort select="@id" order="descending" data-type="number"/>

</xsl:apply-templates>

</xsl:copy>
</xsl:template>

<xsl:template match="div/ul/li/ul/li/ul/li">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()">
<xsl:sort select="@id" />

</xsl:apply-templates>

</xsl:copy>
</xsl:template>

I am able sort succesfully but the highligted elements are missing. Could you please let me know where I am doing wrong

part of out put

<div>
<ul id="2010">
<li>
<input type="checkbox" />
<label for="item-0" class="taxonomy">2007</label>

<ul id="8">
<li>
<ul id="20">

Last edited by gullamahi; April 29th, 2013 at 11:50 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT sorting issue? vb89 XSLT 11 February 22nd, 2012 04:32 PM
Sorting in xslt in sharepoint 2010 dhirajvernekar1 BOOK: Professional SharePoint 2010 Branding and User Interface Design 0 July 8th, 2011 07:37 AM
sorting on date column in XSLT Palwi XSLT 1 March 18th, 2008 07:19 AM
Sorting in XSLT hchaudh1 XSLT 1 November 30th, 2005 04:37 AM
pre-sorting in XSLT - help! thebnut XSLT 6 April 6th, 2004 07:45 AM



All times are GMT -4. The time now is 09:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.