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

Re: position of first empty element which is child of

Subject: Re: position of first empty element which is child of nodes p...
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 16 Feb 2001 22:54:38 -0800 (PST)
xslt position child
Hi Brennan,

> And I want to be able to get the position of the first empty "<BdId>" element --
> ("3" in the XML above).  

No, "the position of the first empty "<BdId>" element" is 1.

What is 3 is:

The position (in the list of the "Entry" children of "TRANSACTION") of the first "Entry" element,
which has an "empty" "BdId" child.

The following XPath expression will return this (no need for an xsl:for-each):

count((/TRANSACTION/Entry[BdId and string-length(BdId )=0])[1]/preceding-sibling::Entry) + 1

Dimitre.



Brennan OShea wrote:
Subject: position of first empty element which is child of nodes processed by
"for-each"

I have the following XML:

<TRANSACTION>
        <Entry Index="1">
                <BdId>487</BdId>
        </Entry>
        <Entry Index="2">
                <BdId>798</BdId>
        </Entry>
        <Entry Index="3">
                <BdId/>
        </Entry>
        <Entry Index="4">
                <BdId/>
        </Entry>
        <Entry Index="5">
                <BdId/>
        </Entry>
</TRANSACTION>


and the following XSL:

<xsl:variable name="Num">
        <xsl:for-each select="TRANSACTION/Entry">
                <xsl:choose>
                        <xsl:when test="string-length(./BdId) = 0">
                                <xsl:value-of select="position()"/>
                        </xsl:when>
                </xsl:choose>
        </xsl:for-each>
</xsl:variable>


And I want to be able to get the position of the first empty "<BdId>" element --
("3" in the XML above).   In the XSL above "Num" is set to "345" since I cannot
break out of the for-each loop when the empty <BdId> is encountered.  I saw a
way to do this on the FAQ when what is being tested is an "attribute" of what is
being iterated through but not a child.

Any help will be greatly appreciated.

Brennan








__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

 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.