xsl-list
[Top] [All Lists]

Re: XSLT Problem - Random Order

2003-10-06 00:36:09
If i understand your problem correctly...

Create another xml document sort.xml for example:

<?xml version="1.0"?>
<sort>
 <x order="1">C3</x>
 <x order="2">C2</x>
 <x order="3">C1</x>
</sort>

The where you wish to sort your elements

<xsl:sort data-type="number"
select="document('sort.xml')/sort/x[.=current()/@attributename]/@order"
order="ascending"/>


PA Sport RnD

Andrew Curry
Software Developer

Telephone: 01430 455545
Website:        http://www.pa.press.net

PA News Limited:
Bridgegate, Howden, East Yorkshire, DN14 7AE

Registered Office:
PA News Limited, 292 Vauxhall Bridge Road, London SW1V 1AE. Registered in
England No. 3891053


----- Original Message ----- 
From: "Saurabh Sinha" <i_am_saurabhsinha(_at_)yahoo(_dot_)co(_dot_)in>
To: <XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Monday, October 06, 2003 8:13 AM
Subject: [xsl] XSLT Problem - Random Order


Hi,

Currently I am facing the following problem while
converting documents into HTML from XML. I need help
to solve this.


Thanks,

Saurabh


Problem:

I want to see the output of books.xml file as category
wise. In books.xml 3 categories are given c1, c2, c3
within book elements. I want to see either c3 first or
c2 first in html output. But everytime it is coming as
per .xml document. I am writing the books.xml,
books.xsl below. Can you suggest me what specific
command I have to give in .xsl document.


books.xml
----------

<?xml version="1.0"?>
<books>
<book category="c1">
<title>ABC</title>
<auth>XX</auth>
</book>

<book category="c2">
<title>SSS</title>
<auth>YY</auth>
</book>
<book category="c3">
<title>MNB</title>
<auth>ZZ</auth>
</book>
</books>


books.xsl
------------

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/">
<html>
<head>
</head>
<body>
<table border="1" width="60%" align="center"
cellpadding="0">
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>


<xsl:template match="books">
<xsl:for-each select="//book">

<xsl:choose>

<xsl:when test="@category='c3'">

<tr>
<td align="center">
<xsl:value-of select="title"/>
</td>
<td align="center">
<xsl:value-of select="auth"/>
</td>
</tr>
</xsl:when>


<xsl:when test="@category='c1'">

<tr>
<td align="center">
<xsl:value-of select="title"/>
</td>
<td align="center">
<xsl:value-of select="auth"/>
</td>
</tr>
</xsl:when>


<xsl:when test="@category='c2'">
<tr>
<td align="center">
<xsl:value-of select="title"/>
</td>
<td align="center">
<xsl:value-of select="auth"/>
</td>
</tr>
</xsl:when>

</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>




books.html
----------

Current Output
--------------


Category Author
-------- -------

ABC XX

SSS YY

MNB ZZ


Expected Output
---------------

Category Author
-------- -------

MNB ZZ

ABC XX

SSS YY


________________________________________________________________________
Yahoo! India Matrimony: Find your partner online.
Go to http://yahoo.shaadi.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>