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

Re: Problem with Predicate selecting only first node r

Subject: Re: Problem with Predicate selecting only first node rather than all but last
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 19 Jan 2001 09:15:08 GMT
idx1
> . I was right, the count for $dups 
> is always 2 even if there are 3 or more present. 

without any input or complete stylesheet its a bit hard to test this,
I fleshed out your code so that it does run (run the following
stylesheet giving anything, eg itself, as input) Your code does
seem to work, I get
  dups: 2 
  dupsall: 3 
  dups: 4 
  dupsall: 5 
  dups: 0 
  dupsall: 1 
  dups: 3 
  dupsall: 4

for the example included, which is I think what you want.

I left the code as it was but it does seem excessivelt complicated for
what it does, all the variable definitions etc. Also if your idx1
elements only have text, then 
[not(./text()=following::idx1/text())]
can be more simply written
[not(.=following::idx1)]

and
[not(position()=count($dupsall))]/idx1"/> 
could be written as 
[not(position()=last()]/idx1"/> 

(which means perhaps that your idx1 elements don't just contain text,
otherwise there is not a lot of point in collecting all these nodes
which you know in advance are the same)

David


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                >

<xsl:output method="xml" indent="yes"/>

<xsl:variable name="x">
 <indexentry><idx1>a</idx1></indexentry>
 <indexentry><idx1>a</idx1></indexentry>
 <indexentry><idx1>a</idx1></indexentry>
 <indexentry><idx1>b</idx1></indexentry>
 <indexentry><idx1>b</idx1></indexentry>
 <indexentry><idx1>b</idx1></indexentry>
 <indexentry><idx1>b</idx1></indexentry>
 <indexentry><idx1>b</idx1></indexentry>
 <indexentry><idx1>c</idx1></indexentry>
 <indexentry><idx1>d</idx1></indexentry>
 <indexentry><idx1>d</idx1></indexentry>
 <indexentry><idx1>d</idx1></indexentry>
 <indexentry><idx1>d</idx1></indexentry>
</xsl:variable>

<xsl:variable name="idx" select="document('')/*/*[indexentry]"/>


 <xsl:variable name="entries" select="$idx//indexentry"/>
 <xsl:variable name="primes"
select="$entries/idx1[not(./text()=following::idx1/text())]"/>

<xsl:template match="/">
 <xsl:for-each select="$primes">
  <xsl:variable name="thisprime" select="./text()"/>
  <xsl:variable name="dupsall"
select="$entries[idx1[(./text()=$thisprime)]]"/>
  <xsl:variable name="dups"
select="$dupsall[not(position()=count($dupsall))]/idx1"/> 
  dups: <xsl:value-of select="count($dups)"/> 
  dupsall: <xsl:value-of select="count($dupsall)"/> 
 </xsl:for-each> 
</xsl:template>



</xsl:stylesheet> 

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 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.