[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] RE: XSLT - How to find the last element in a group of nodes inside of a for loop


Subject: [xsl] RE: XSLT - How to find the last element in a group of nodes inside of a for loop
From: "Wei, Alice J." <ajwei@xxxxxxxxxxx>
Date: Thu, 17 Jan 2008 14:26:02 -0500

Hi,

  Referring to your question, have you tried using <xsl:value-of
select="@zone[last()]">?

   I have to point out that if you have no actual value, what you are doing
here is merely extracting the result from what is displayed in the attribute.
Is that what you want?

  As for your code, I am not sure what you want to select in the
<xsl:for-each>
  if there is is no attribute that say competitorTerritory in your input.

I hope this helps.

======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei@xxxxxxxxxxx
________________________________________
From: Chaudhary, Harsh [HCHAUDHA@xxxxxxxxx]
Sent: Thursday, January 17, 2008 2:10 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] XSLT - How to find the last element in a group of nodes inside
of a for loop

This is a duplicate of my previous email. I accidently sent out the
wrong Subject. Sorry about that.

-----Original Message-----
From: Chaudhary, Harsh
Sent: Thursday, January 17, 2008 1:08 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Announcement: Dexter - XSL Transform Generation Tool


Hi,

I am writing a table using XSLT 1.0. The sort key to the table is the
"Zone". A table can have multiple zones. There are also a couple of
columns as show below. The requirement is to first sort the table by
Zone and then by Territory. The value in the Number row will appear for
only the last row for any give zone.

So a table will look something like:

Zone    Territory       Number
1       1
1       2
1       3               25
2       1               12
3       1               7
4       1
4       2               50

I am using the Meunichian method to group all rows by Zone and then on
the inner for-each for the meunichian code, I am sorting by Territory.
So far so good.

My question is, how do I detect the last row for each zone?

Input XML:

<root>
        <row>
                <zone code='1' territory='1' number='25'>
                <zone code='1' territory='2' number='25'>
                <zone code='1' territory='3' number='25'>
                <zone code='2' territory='1' number='12'>
                <zone code='3' territory='1' number='7'>
                <zone code='4' territory='1' number='50'>
                <zone code='4' territory='2' number='50'>
        </row>
</root>


<xsl:for-each select="//competitor[generate-id() =
generate-id(key('someKey', @zone))]">

        <xsl:sort select="@zone"/>
        <xsl:for-each select="key('someKey', @zone)">

                <xsl:sort select="@competitorTerritory"/>
                        //Some code

                        //How do I detect the last row for each Zone?
        </xsl:for-each>
</xsl:for-each>

Would appreciate your help. If I left some information out, please let
me know.

Thanks,
HC.


Current Thread
Keywords