[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: Displaying every 2 element values in 1 row
Subject: Re: Displaying every 2 element values in 1 row From: "Noah Nordrum" <noah@xxxxxxxxxxxxx> Date: Wed, 26 Apr 2000 00:07:10 -0400 |
ok, this works all fine and dandy for that example, but with a more complicated example this gets wacked. XML(imagine there is data in there ;]): <company> <department> <name></name> <person> <name></name> </person> <person> <name></name> </person> </department> <department> <name></name> <person> <name></name> </person> <person> <name></name> </person> </department> <department> <name></name> <person> <name></name> </person> <person> <name></name> </person> </department> <department> <name></name> <person> <name></name> </person> <person> <name></name> </person> </department> </company> so I basicly want this output: <tr><td>DEPARTMENT 1</td>DEPARTMENT 2</td></tr> <tr><td>DEPARTMENT 3</td>DEPARTMENT 4</td></tr> so this would be the <td> part: <xsl:template match="department"> <td> <xsl:value-of select="name" /><br /> <ul> <xsl:apply-templates select="person" /> </ul> </td> </xsl:template> <xsl:template match="person"> <li><xsl:value-of select="name" /></li> </xsl:template> this is slightly over-slimplified, but it shows the problem I am having of that I am not trying to call a <xsl:value-of> as the contents of the tiling, but calling an <xsl:apply-templates>. the "following-sibling" returns a node-set that consists of "all nodes that start after the end of the current node and have the same parent as the current node"("XML Bible" Table 14-2). The problem is that the first time you call the "following-sibling" it returns the following <person> and all other <person> elements in the <department> element. This is fine if there are only 2 <person> elements in a <department>. If there are 3 or more, it causes some nasty recursion that I have yet to figure out how to avoid. Thanks for any help in advance, Noah Nordrum p.s. This time I will also check the list archives, since it appears I'm not getting 100% of the messages from the list :) Mike Brown wrote: > > How can I display every two element node values in one row by checking the > > position? > > > > If I have an xml like: > > > > <eno>A21</eno> > > <eno>A22</eno> > > <eno>A23</eno> > > <eno>A24</eno> > > <eno>A25</eno> > > <eno>A26</eno> > > <!-- look at every 1st, 3rd, 5th, etc 'eno' element child of current node --> > <xsl:for-each select="eno[position() mod 2 = 1]"> > <!-- start a new table row --> > <tr> > <!-- cell 1: value of current 'eno' --> > <td> > <xsl:value-of select="."/> > </td> > <!-- cell 2: value of next 'eno' or a non-breaking space if none --> > <td> > <xsl:choose> > <xsl:when test="following-sibling::eno"> > <xsl:value-of select="following-sibling::eno"/> > </xsl:when> > <xsl:otherwise> </xsl:otherwise> > </td> > </tr> > </xsl:for-each> > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
begin:vcard n:Nordrum;Noah tel;cell:612 940 3710 tel;home:919 460 2813 tel;work:919 678 0300 x-mozilla-html:FALSE url:www.activated.com org:Activated Intelligence, LLC;Headlinewatch.com adr:;;1001 Winstead Drive;Cary;NC;27513;US version:2.1 email;internet:noah@xxxxxxxxxxxxx title:Developer note:Activated Intelligence - Bringing Life To The Net, and The Net To Life fn:Noah Nordrum end:vcard
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Displaying every 2 element valu, Mike Brown | Thread | Re: Displaying every 2 element valu, Mike Brown |
Re: display in a recursive way, Paul Tchistopolskii | Date | Re: display in a recursive way, Paul Tchistopolskii |
Month |
Keywords