[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

looking ahead during a for-each

Subject: looking ahead during a for-each
From: "Michael Beddow" <mbnospam@xxxxxxxxxxx>
Date: Mon, 7 May 2001 23:04:19 +0100
trans lover
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.