|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Grouping while sorting
Hello all,
I seem to be caught on trying to sort something while at the same time grouping them. In the first input (see below), I have no problems, but the second gives me problems in the current solution. The problem seems that I get the nodes in sorted order, but the test on the previous sibling goes to the document order. How do I make the test so that I can group these elements, and still retain the sorted order? Thank you very much in advance! Ragulf Pickaxe <?xml version="1.0"> <Root> <!-- Input 1 --> <Elem GroupID="A" Order="1">A1</Elem> <Elem GroupID="A" Order="2">A2</Elem> <Elem GroupID="B" Order="4">B4</Elem> <Elem GroupID="A" Order="5">A5</Elem> <Elem GroupID="C" Order="1">C1</Elem> <Elem GroupID="B" Order="7">A7</Elem> </Root>
<?xml version="1.0"> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <Output> <xsl:apply-templates select="Root"/> </Output> </xsl:template> <xsl:template match="Root"> <xsl:apply-templates select="Elem"> <xsl:sort select="@GroupID"> <xsl:sort select="@Order" data-type="number"> </xsl:apply-templates> </xsl:template> <xsl:template match="Elem"> <xsl:if test="not(preceding-sibling::Elem/@GroupID=current()/@GroupID)"> <Group><xsl:value-of select="@GroupID"/></Group> </xsl:if> <xsl:value-of select="."/> - </xsl:template> </xsl:stylesheet>
Output from input 2 <Output> A1 - A2 - A5 - <Group>A</Group>A7 - <Group>B</Group>B4 - <Group>C</Group>C1 - </Output> (Summary: I would very much like to get second output to be the same as the first output - I hope that this is possible). _________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








