Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2013, 05:02 AM
Registered User
 
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..





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT sorting issue? vb89 XSLT 11 February 22nd, 2012 05: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 05:37 AM
pre-sorting in XSLT - help! thebnut XSLT 6 April 6th, 2004 07:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.