Subject: RE: [xsl] looking ahead during a for-each From: "Xuegen Jin" <xjin_imi@xxxxxxxxx> Date: Mon, 7 May 2001 18:38:18 -0400 |
replace following-sibling::sense/@n with following-sibling::sense[1]/@n -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Michael Beddow Sent: Monday, May 07, 2001 6:04 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] looking ahead during a for-each I expect I've got something really obvious very wrong, but I can't work it out, so here's hoping: My xml simplifies to this: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="test1.xsl"?> <entry> <divgen/> <sense n="1"> <trans>young man</trans> </sense> <sense> <trans>knight bachelor</trans> </sense> <sense> <trans>junior member of gild</trans> </sense> <sense n="2"> <trans>unmarried man</trans> </sense> <sense> <trans>lover</trans> </sense> <sense n="3"> <trans>champion</trans> </sense> <sense> <trans>officer</trans> </sense> <sense n="4"> <trans>bachelor</trans> </sense> <sense n="5"> <trans>servant</trans> </sense> </entry> My xsl needs to iterate over this group of sense elements, treating each one differently depending on whether the NEXT sense element in document order has an n attribute. (the dtd, which I've left out here, does not require an n attribute or set a default value for it) To illustrate my problem, here's the xsl structure with much simplified content: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="entry"> <xsl:apply-templates/> </xsl:template> <xsl:template match="*"> </xsl:template> <xsl:template match ="divgen"> <xsl:for-each select="following-sibling::sense"> <xsl:choose> <xsl:when test="following-sibling::sense/@n"> <br/>Next sense has n value <xsl:value-of select="following-sibling::sense/@n"/> </xsl:when> <xsl:otherwise> <br/> Next sense has no n value </xsl:otherwise> </xsl:choose> Next sense has trans "<xsl:value-ofselect="following-sibling::sense/trans"/>" </xsl:for-each> </xsl:template> </xsl:stylesheet> Now the actual output this gives me is: Next sense has n value 2 Next sense has trans "knight bachelor" Next sense has n value 2 Next sense has trans "junior member of gild" Next sense has n value 2 Next sense has trans "unmarried man" Next sense has n value 3 Next sense has trans "lover" Next sense has n value 3 Next sense has trans "champion" Next sense has n value 4 Next sense has trans "officer" Next sense has n value 4 Next sense has trans "bachelor" Next sense has n value 5 Next sense has trans "servant" Next sense has no n value Next sense has trans "" i.e the results of two value-of selects are not in synch though the syntax suggests they ought to be What I *expected* to see was something like: Next sense has no n value Next sense has trans "knight bachelor" Next sense has no n value Next sense has trans "junior member of gild" Next sense has n value 2 Next sense has trans "unmarried man" Next sense has no n value Next sense has trans "lover" Next sense has n value 3 Next sense has trans "champion" Next sense has no n value Next sense has trans "officer" Next sense has n value 4 Next sense has trans "bachelor" Next sense has n value 5 Next sense has trans "servant" Next sense has no n value Next sense has trans "" Can anybody explain why I get these results, and how I can get the ones I want (i.e. how within a for-each iteration I can see whether the next sibling has a given attribute or not?) Thanks in advance Michael ------------------------------------------------- Michael Beddow http://www.mbeddow.net/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] looking ahead during a for-e, Michael Beddow | Thread | RE: [xsl] looking ahead during a f, Michael Kay |
Re: [xsl] looking ahead during a f, Larry_Mason | Date | [xsl] wysiwyg xml editing, Mattias Konradsson |
Month |