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

Re: How Can You Exit an xsl:for-each Loop Prematurely?

Subject: Re: How Can You Exit an xsl:for-each Loop Prematurely?
From: "Dan Machak" <machak@xxxxxxxxxxxx>
Date: Thu, 23 Sep 1999 11:37:57 -0700
xsl for each exit
On Sep 23, 12:58pm, Michael Teigman wrote:
You can try a different approach:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="/">
	<xsl:apply-templates select="(Salesman/Orders[not(@Order='')])[1]"/>
</xsl:template>

<xsl:template match="Orders">
  <order-val>
  	<xsl:value-of select="@Order"/>
  </order-val>
</xsl:template>

</xsl:stylesheet>

This yields:
<order-val>zzzzzzzzz</order-val>

The select clause chooses the first Orders element that has a non-null Order
attribute.

Dan

> Subject: RE: How Can You Exit an xsl:for-each Loop Prematurely?
>
> My source XML has an element with a set of attributes with the same name
e.g.,
>
> <Salesman>
>      <Orders Order=""/>
>      <Orders Order=""/>
>      <Orders Order="zzzzzzzzz"/>
>      <Orders Order="ee"/>
> </Salesman>
>
> To simplify, I am doing the equivalent of trying to find the first non-null
> Order, e.g.:
>
> <xsl:for-each select="//Salesman/Orders/@Order">
>      <xsl:variable name="orderID">
>                     <xsl:value-of select="."/>
>      </xsl:variable>
>      <xsl:if test="string-length($orderID) > 0">
>           ..... output something .....
>      </xsl:if>
> </xsl:for-each>
>
> I want only the first output. I do not want multiple outputs.
>
> How could I exit after the first or suppress the additional outputs after I
have
> found one?
>
>      mike
>
>
>
>
>  (Embedded
>  image moved   "Harbarth, Juliane" <jhb@xxxxxxxxxxxxxx>
>  to file:      09/23/99 10:43 AM
>  pic06086.pcx)
>
>
>
>
> Please respond to xsl-list@xxxxxxxxxxxxxxxx
>
> To:   xsl-list@xxxxxxxxxxxxxxxx
> cc:    (bcc: Michael Teigman/HPG/US/Reuters)
> Subject:  RE: How Can You Exit an xsl:for-each Loop Prematurely?
>
>
>
>
>
>
>
> > From: Michael Teigman [mailto:michael.teigman@xxxxxxxxxxx]
> > Sent: Thursday, September 23, 1999 1:31 AM
> > To: xsl-list@xxxxxxxxxxxxxxxx
> > Subject: How Can You Exit an xsl:for-each Loop Prematurely?
> >
> > Is there some way to exit an xsl:for-each loop before all the nodes have
> been
> > evaluated?
>
> I can't think of anything to achieve that.
> Can you give some more details of what you are trying to do ?
>
> Juliane.
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
> ------------------------------------------------------------------------
> Any views expressed in this message are those of the individual  sender,
> except  where  the  sender  specifically  states them to be the views of
> Reuters Ltd.
>
> [ Attachment (application/octet-stream): "pic06086.pcx" 3279 bytes
>   Encoded with "base64" ]
>-- End of excerpt from Michael Teigman



-- 
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<> Dan Machak                    <>  machak@xxxxxxxxxxxx  <>
<> MS T27A-1                     <>  650-604-2388 (VOICE) <>
<> NASA Ames Research Center     <>  650-604-3957 (FAX)   <>
<> Moffett Field, CA 94035-1000  <>                       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>


 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.