xsl-list
[Top] [All Lists]

RE: seemingly simple transform, need idea how to do it.

2002-10-09 12:17:24
Hi Trevor, thanks for the response.

I will let others on the list complain about the 'jump out of the
loop' bit ;-)
do you mean they would complain about what I am doing in the stylesheet or how 
I described it?

I rewrote the stylesheet to jump out of the [../@firstName = 'Johnny'] filtered 
for-each loop to get the 'Billy' info to go based on date instead of position 
like you said.  The output is the same as before.

here is the stylesheet rewritten:
------------------------------------------------
<xsl:for-each select="people/person/date[../@firstName = 'Johnny']">
  <xsl:sort select="funThing" order="ascending" data-type="text"/>
  <xsl:variable name="myDate" select="@day"/>
  <tr>
    <td><xsl:value-of select="@day"/></td>
    <td><xsl:value-of select="funThing"/></td>
    <td><xsl:value-of select="badThing"/></td>
    <td><xsl:for-each select="../../person/date[../@firstName = 
'Billy'][(_at_)day = $myDate]"><xsl:value-of 
select="funThing"/></xsl:for-each></td>
    <td><xsl:for-each select="../../person/date[../@firstName = 
'Billy'][(_at_)day = $myDate]"><xsl:value-of 
select="badThing"/></xsl:for-each></td>
  </tr>
</xsl:for-each>
------------------------------------------------
In this particular xml, I know that Johnny and Billy will always do a funThing 
and a badThing on always the same day, so the grouping solution is not an issue.

My problem is I cant set the sort to work off of either Billy column because 
the outer for-each is filtered based on Johnny.
this doesn't work:
<xsl:sort select="funThing[../@firstName = 'Billy']" order="ascending" 
data-type="text"/>

anyway, is the answer to copy the node-set of the Johnny set of dates and the 
node set of the billy set of dates and then do the for each over that?

thanks for the response.
will

-----Original Message-----
From: Trevor Nash [mailto:tcn(_at_)melvaig(_dot_)co(_dot_)uk]
Sent: Wednesday, October 09, 2002 12:59 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: Carter, Will
Subject: Re: [xsl] seemingly simple transform, need idea how to do it.


On Tue, 8 Oct 2002 08:48:07 -0500, Will Carter wrote:

I want to be able to sort on the Billy funThing or Billy badThing columns. 
Seems like I am doing too much to set variable with position, 
jump out of that loop to get the Billy contents.

I will let others on the list complain about the 'jump out of the
loop' bit ;-)

I guess your problem is that if the input XML is not in date order
already, the 'Johnny' columns get sorted OK but the 'Billy' columns
stay in document order?

That is because the position you are saving is the position in the
sorted node list, so the earliest date will always be position 1.
Then when you use this number to pick a Billy node, you will get the
first in the document regardless of what date it is.

So: find the Billy information by selecting on the date rather than
the position.

When you have that working, come back to the FAQ and look up grouping
using xsl:key (called 'Meunchian grouping').  That will let you do
neat things like cope with input where Billy and Johnny do things on
different days, so you have to leave some of the columns blank.

Hope that helps,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn(_at_)melvaig(_dot_)co(_dot_)uk

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



<Prev in Thread] Current Thread [Next in Thread>