Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Strange problem with count

From: rob.guitar.rob@-----.---
To: NULL
Date: 8/1/2005 6:24:00 PM
Hello,

My last few posts have been revolving aroung the same problem, and I
still cant solve it and I would be really appreciate if anyone could
spot a problem.

a section of my XML goes like

....
     <parent>
         <child>
             <grandchild1>
             <grandchild2>
         <child>
     <parent>

/...

I need to describe a numeric link between grandchild elements and the
child elements.

I have been using count(preceding::*) to id the cells numerically:


<xsl:template select="grandchild1|grandchild2">
  <MyID>
     Child:      <xsl:value-of select="count(../preceding::*)"/>
     Grandchild: <xsl:value-of select="count(./preceding::*)"/>
  </MyID>
</xsl:template>


However, the first grandchild1 element that runs this has the same
count as the child element. (35 and 35).  The second grandchild element
that runs is incremented by one as expected, 35 and 36, meaning it
seems 1 too low.  The obvious problem is the first counts are returned
the same, negating the idea of unique numeric ID's.

Are these results to be expected?  I do not know why/how the ../ and ./
return the same value (surely the ../preceding has come back a node in
that first case and therefore should be -1 of the grandchild1?)

I know a simple fix is just to add one onto all of the grandchilds
(count(./preceding::*)+1) but it seems slight dodgey, i.e. a fix to a
potential problem in my XSL.

I would really appreciate is anyone could help me understand why this
does not work, so that I can fix it properly.

Any help will again be most appreciated.

Thanks, Rob.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent