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 21st, 2006, 09:30 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouped and sorted table row numbers

Good morning,

Given this input:

<Product>
    <ProductType>Non-Subscription</ProductType>
    <ProductGrouping>License 1</ProductGrouping>
    <ProductName>Renewal</ProductName>
</Product>
<Product>
    <ProductType>Subscription</ProductType>
    <ProductGrouping>License 1</ProductGrouping>
    <ProductName>New</ProductName>
</Product>
<Product>
    <ProductType>Subscription</ProductType>
    <ProductGrouping>License 2</ProductGrouping>
    <ProductName>Renewal</ProductName>
</Product>
<Product>
    <ProductType>Subscription</ProductType>
    <ProductGrouping>License 2</ProductGrouping>
    <ProductName>New</ProductName>
</Product>


I am sorting and grouping to create a table in WordML:

<xsl:for-each select="//ProductName[generate-id()=generate-id(key('subscriptionProducts', preceding-sibling::ProductGrouping) [1])]">
    <xsl:sort select="preceding-sibling::ProductType='Subscription'" order="descending"/>
    <xsl:sort select="preceding-sibling::ProductGrouping"/>
etc.
...

<xsl:for-each select="key('subscriptionProducts', preceding-sibling::ProductGrouping)">
    <xsl:sort select="."/>
etc.

Which seems to be working correctly, producing:

Subscription
    License 1
        New
    License 2
        New
        Renewal
Non-Subscription
    License 1
        Renewal

But then, in order to generate cell formulas, I need to find the sorted row number of each New or Renewal row, producing something like:

Subscription
    License 1
        New =C3
    License 2
        New =C5
        Renewal =C6
Non-Subscription
    License 1
        Renewal =C9


Is this possible? Using position() seems promising but I've been wading through the FAQs and just can't seem to wrap my head around how it would work with the nested for-each loops.

Any help would be much appreciated.

Many thanks,

Allison

 
Old April 24th, 2006, 10:06 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good morning,

Well, it looks like the solution to this is the node-set() extension function. I was able to wrap the generated table within a variable and then access the sorted row numbers.

<xsl:for-each select="exsl:node-set($temporary-tree)/w:tr">
<xsl:variable name="rowPos" select="position()"/>

Allison






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems rendering to a table with sorted results jlmacdonald XSLT 6 March 27th, 2008 05:54 PM
How to get least value numbers in a sorted array? ashokparchuri Other Programming Languages 3 December 5th, 2006 09:25 AM
UPDATING 1 row with another row in same table rit01 SQL Server 2000 3 February 19th, 2006 08:55 AM
sorted table crmpicco Javascript How-To 0 March 17th, 2005 10:29 AM
numbers on grouped records mkapler Access 2 March 6th, 2005 05:49 PM





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