[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT Problem - Random Order

Subject: Re: XSLT Problem - Random Order
From: Mukul Gandhi <mukulgw3@xxxxxxxxx>
Date: Mon, 6 Oct 2003 01:56:03 -0700 (PDT)
xsl for each random
Hi Saurabh,
  From your problem description, it seems that *there
should not be <xsl:choose & <xsl:when* . In your XSL,
xsl:choose does not have any effect when you are doing
xsl:for-each. If you want to see c3 first or c2 first,
then it seems you should hardcode the order in the
XSL(as I have written in my XSL). I feel you should
also not do <xsl:for-each select="//book"> . I feel
<xsl:for-each select="book"> is better that //book. a
// construct searches the XML to arbitrary depths,
which is inefficient. Also, in my opinion,  a
xsl:for-each is not required for this problem..

Below is the complete 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">
	<tr>
	 <td align="center">
	  <xsl:value-of select="books/book[@category =
'c3']/title"/>
	 </td>
	 <td align="center">
	   <xsl:value-of select="books/book[@category =
'c3']/auth"/>
	 </td>
	</tr>
	<tr>
 	  <td align="center">
	   <xsl:value-of select="books/book[@category =
'c1']/title"/>
	  </td>
	  <td align="center">
	    <xsl:value-of select="books/book[@category =
'c1']/auth"/>
	  </td>
	</tr>
        <tr>
	  <td align="center">
	   <xsl:value-of select="books/book[@category =
'c2']/title"/>
	  </td>
	  <td align="center">
	   <xsl:value-of select="books/book[@category =
'c2']/auth"/>
	  </td>
	</tr>
   </table>
 </body>
 </html>
</xsl:template>
</xsl:stylesheet>

Hope I understood the problem correctly.

Regards,
Mukul


--- Saurabh Sinha <i_am_saurabhsinha@xxxxxxxxxxx>
wrote:
> 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
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.