Subject: [xsl] looking ahead during a for-each From: "Michael Beddow" <mbnospam@xxxxxxxxxxx> Date: Mon, 7 May 2001 23:04:19 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] javascript and xsl, Michael Kay | Thread | RE: [xsl] looking ahead during a f, Xuegen Jin |
RE: [xsl] parsing strings, Paul Brown | Date | Re: [xsl] looking ahead during a f, Larry_Mason |
Month |