Subject: Re: [xsl] Accessing specific repetitive node From: "Mark Williams" <mark@xxxxxxxxxxx> Date: Fri, 5 Mar 2004 12:36:07 -0000 |
Ken, Thanks for the response. On this occasion, I was trying to access items 1, 3 & 5, but it could be any items and I do not know in advance, which is why I need to select by position reference. Any ideas why this might not be working. It may help you to see the response I just posted to David on this topic. Thanks, Mark ----- Original Message ----- From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> To: "XSL-List" <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> Sent: Friday, March 05, 2004 12:15 PM Subject: Re: [xsl] Accessing specific repetitive node > At 2004-03-05 11:47 +0000, Mark Williams wrote: > >The XML looks like this > > > ><DATA> > > <Table ID="2"> > > <Data> > > <Code>1</Code> > > <Code>2</Code> > > <Code>3</Code> > > <Code>4</Code> > > <Code>5</Code> > > </Data> > > </Table> > ></DATA> > > > >I need to access the first 1, 3 and 5 items. > > Is it that you need to return all odd-numbered items? Or do you need just > the first, third and fifth items of all sets? > > >I have tried it in the > >following ways: > > > > <xsl:value-of select="DATA/Table[@ID='2']/Data/Code[1]" /> //this works > >okay > > <xsl:value-of select="DATA/Table[@ID='2']/Data/Code[position()=1]" /> > >//this also works okay > > Those two are equivalent: the first is the abbreviation of the second. > > <xsl:value-of> returns only a single item so you cannot use it to return > multiple items. > > To access every odd item in the list you could use modulus arithmetic: > > <xsl:for-each select="DATA/Table[@ID='2']/Data/Code[position() mod 2 = 1]"> > <xsl:if test="position() > 1">, </xsl:if> > <xsl:value-of select="."/> > </xsl:for-each> > > I hope this helps. > > .............................. Ken > > -- > US XSL training: Washington,DC March 15; San Francisco,CA March 22 > World-wide on-site corporate, government & user group XML training > G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx > Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ > Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) > Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Accessing specific repeti, G. Ken Holman | Thread | [xsl] Generating HTML table, Andreas Lindahl |
Re: [xsl] Accessing specific repeti, Mark Williams | Date | [xsl] general problem with variable, Sebastian Fey |
Month |