[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Inconsistent solution from a conditional data-set

Subject: Re: Inconsistent solution from a conditional data-set by group methods
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Apr 2001 08:11:35 +0100
conditional formatting inconsistent access
Hi Yang,

> Using Muenchian procedures , I define key function as following phrase,
> <xsl:key name="Listings" match="line" use="name" />

Here, you're indexing *all* the line elements by their name.  So when
you access the key with some particular name, then you get all the
line elements with that name, including those for which it's not true
that substring(salesno, 10, 2) = '03'.

> and then supposedly obtain a set of unique set of name listing from:
> <xsl:for-each
> select="//line[substring(salesno,10,2)='03'][generate-id(.)=generate-id(key(
> 'Listings',name)[1])]">
>   <xsl:value-of select="name"/>
> </xsl:for-each>

Now here, you're going through *only* those line elements where
substring(salesno, 10, 2) = '03' is true.  You're testing whether each
of those line elements is the same as the first line element that you
get when you retrieve the lines with that name using the key.  So,
take a look at the lines named AAA in your source:

<line><name>AAA</name><salesno>B001-1-0101110093</salesno></line>
...
<line><name>AAA</name><salesno>B001-1-0101110096</salesno></line>
...
<line><name>AAA</name><salesno>A001-1-0103010001</salesno></line>
...

You're only looking at that third line.  When you call the key(), then
the *first* line is returned, because it's the first line in the
document with the name 'AAA'.  Since that line isn't the same as the
third line, then you don't get the third line coming out of the
xsl:for-each.

> So I change key function by adding predicates
> [substring(salesno,10,2)='03'] , such as

Yes - that will only index the lines that you're actually interested
in (which is a good idea anyway - it's good to keep key hashtables
small so that they don't take up too much memory).

> <xsl:key name="Listing2" match="line[substring(salesno,10,2)='03']"
use="name"/>>
> then use it with for-each element and then get a good solution this
> time.

That's right, because the third line in the above will be the *first*
one returned by the key - it won't see the first two because they
don't match the key's match pattern.

BTW, if you have unique salesno elements for all your lines, then
rather than generating IDs for each line (which can take time), then
you could use the salesno elements as the basis of the comparison.  So
change the xsl:for-each select to:

   /docs/line[substring(salesno,10,2)='03']
             [salesno = key('Listing2',name)[1]/salesno]

I hope that clarifies things a bit.  Do ask further questions if
there's something that's still unclear.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.