Hi David –
Ah. Ok, so if I understand correctly, I need to change the variable assignment
to grab the position of the <DATA> element within the parent <ROW>, rather than
within the for-each? How would I do that?
But then also, why didn’t the second option work, where I for-each all the
<DATA> elements and then test the position (<xsl:if test="position() > 1" />)?
Thanks
Michele
From: David Carlisle d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Friday, March 5, 2021 2:09 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] position() > 1 not working
there are 4 DATA children so
<xsl:for-each select="fmp:COL[3]/fmp:DATA[position() > 1]">
selects the 2nd, 3rd and 4th
the scope of that position() is just that step of the xpath, within the body of
the for-each, position() counts the selected items
so as there are three items selected position() as stored in $parent-position
will have values 1,2,3 which is one less than you expected.
David
On Fri, 5 Mar 2021 at 18:54, Michele R Combs
mrrothen(_at_)syr(_dot_)edu<mailto:mrrothen(_at_)syr(_dot_)edu>
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
wrote:
I want to select all the child <DATA> elements of a <COL> except for the first
one. I’ve tried several different things but I must be missing something
stupidly obvious since it isn’t working.
Input data:
<ROW>
<COL><DATA></DATA></COL>
<COL><DATA>Adult Education Audio and Video Collection</DATA></COL>
<COL>
<DATA>SULF</DATA>
<DATA>Bird</DATA>
<DATA>Bird</DATA>
<DATA>Hawkins</DATA>
<COL>
<COL>
<DATA></DATA>
<DATA>24:F:4</DATA>
<DATA>36:G:5-7</DATA>
<DATA>234:A:1-5</DATA>
<COL>
<COL>
<DATA>Box 1-22</DATA>
<DATA>Adds, 3 boxes</DATA>
<DATA>Box 23-45</DATA>
<DATA>Oversize items</DATA>
<COL>
</ROW>
In my XSL:
<xsl:for-each select="fmp:COL[3]/fmp:DATA[position() > 1]">
<xsl:variable name="parent-position" select="position()" />
<xsl:value-of select="../../fmp:COL[3]/fmp:DATA[$parent-position]"/>
<xsl:value-of select="../../fmp:COL[4]/fmp:DATA[$parent-position]"/>
<xsl:value-of select="../../fmp:COL[5]/fmp:DATA[$parent-position]"/>
</xsl:for-each>
Expected output:
Bird 24:F:4 Adds, 3 boxes
Bird 36:G:5-7 Box 23-45
Hawkins 234:A:1-5 Oversize items
Actual output:
SULF Box 1-22
Bird 24:F:4 Adds, 3 boxes
Bird 36:G:5-7 Box 23-45
Hawkins 234:A:1-5 Oversize items
I also tried just getting all the <DATA> elements and then testing the position:
<xsl:for-each select="fmp:COL[3]/fmp:DATA">
<xsl:if test="position() > 1" />
But that gave the same results. Just to be sure I wasn’t crazy, I added an
<xsl:value-of> statement to spit out the value of position() at each point, and
I see exactly what I expect there (1, 2, 3, 4). What am I missing?
Michele
+++++++++
Michele Combs | Lead Archivist
Special Collections Research Center
Visit our blog! library-blog.syr.edu/scrc/<http://library-blog.syr.edu/scrc/>
Syracuse University Libraries
222 Waverly Ave
Syracuse, New York 13244
t 315.443-2081 | e
mrrothen(_at_)syr(_dot_)edu<mailto:mrrothen(_at_)syr(_dot_)edu> | w
scrc.syr.edu<http://scrc.syr.edu>
SYRACUSE UNIVERSITY
syr.edu<http://syr.edu>
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by email)
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/1127818> (by
email<>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--