This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with Predicate selecting only first node rather than all but last



> . 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]