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 28th, 2005, 03:47 PM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 1:M sorting or grouping cant explain :: newbie Q

hi

 I can only do simple xsl and got stuck into this one , i really hope someone can help me out.. I cant think of a soultion.

 This is my XML

 <root>
 <PageType>
   <Type>
    <ID>1</ID>
    <Position>Something</Position>
   </Type>
   <Type>
    <ID>2</ID>
    <Position>Something else</Position>
   </Type>
   ....
 </PageType>
 <PageLet>
   <Page>
      <ID>0</ID>
      <Page_type>1</Page_type>
   </Page>
   .....
   .....
   .....
 </PageLet>
 </root>

 i wish to sort PageLet/Page accoring to its position by Page_type.

 Please dont use a template because i dont know that you 'or cant use it

 Hope can some one help me out

 Many thanks in advance
 auser

 
Old April 28th, 2005, 04:20 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, you haven't given a very clear specification of your requirements. Showing the required output file is usually enough to give people a clue as to what you're wanting.

Secondly, if you don't supply the XSLT code you have written so far, then it's very difficult for people to see where you are having problems or learning difficulties.

Thirdly: "Please don't use a template". Sorry, but writing sorting and grouping in XSLT 1.0 is hard enough if you use the full language, but trying to do it without templates is like asking someone to show you how to play a Beethoven piano concerto with one hand.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 28th, 2005, 04:58 PM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:.. but trying to do it without templates is like asking someone to show you how to play a Beethoven piano concerto with one hand...
Ohh dear sorry my mistake.

oky , let me explain quicky. for example i have 10 PageTypes and 20 Pages in Pagelet . for simplicity i like to show the ID of the page sorted by the Page_type

<root>
 <PageType>
   <Type>
    <ID>1</ID>
    <Position>2</Position>
   </Type>
   <Type>
    <ID>2</ID>
    <Position>1</Position>
   </Type>
 </PageType>
<PageLet>
   <Page>
      <ID>0</ID>
      <Page_type>1</Page_type>
   </Page>
   <Page>
      <ID>11</ID>
      <Page_type>2</Page_type>
   </Page>
   <Page>
      <ID>22</ID>
      <Page_type>1</Page_type>
   </Page>
 </PageLet>
</root>

<xsl:for-each="//PageLet/Page">
   <xsl:sort select="//PageType/Type[ID=Page_type]/Position" data-type="number"/>
  <xsl:value-of select="ID"/>,
</xsl:for>

displays results as:

0,22,11


************
sorry for not explaining more

any comments?

again Thanks
br
auser









 
Old April 29th, 2005, 02:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:sort select="//PageType/Type[ID=Page_type]/Position" data-type="number"/>

The problem is that the context changes inside the predicate: both ID and Page_type are taken as children of the Type element. You want

<xsl:sort select="//PageType/Type[ID=current()/Page_type]/Position" data-type="number"/>

MK

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 29th, 2005, 11:57 AM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great 'Thumbs UP

It works just fine : )

now i know i should read more : / lol

Many thanks for this solution , if there is something besides xsl i can be of anyhelp please say.

mhkay <--- your the man

br
auser






Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie - grouping from different areas? wilgartw XSLT 5 October 30th, 2007 09:46 AM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
Grouping and (dynamic) sorting asearle XSLT 12 November 10th, 2006 10:51 AM
Section Grouping (XSL Newbie!) vjlomas XSLT 1 February 4th, 2005 04:00 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM





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