|
Subject: Re: How Can You Exit an xsl:for-each Loop Prematurely? From: Michael Teigman <michael.teigman@xxxxxxxxxxx> Date: Thu, 23 Sep 1999 15:33:12 -0400 |
I was afraid that using the example with a null was going to oversimplify the
problem.
Here is a portion of my actual XLM which I am supplied and have no control over.
<METADATA>
<CODES CLASS="CATEGORY">
<CODE CODE="NEWS"/>
<CODE CODE="IT"/>
<CODE CODE="DE"/>
<CODE CODE="EUROPE"/>
<CODE CODE="CRIM"/>
<CODE CODE="GB"/>
<CODE CODE="ODD"/>
</CODES>
</METADATA>
<StringMap>
<textIn SupCat="AAA" iCat="Ratings News"/>
<textIn SupCat="ADV" iCat="Advertising"/>
<textIn SupCat="ODD" iCat="Human Interest"/>
<textIn SupCat="GB" iCat="Great Britain"/>
</StringMap>
The actual transformation is to see if any CODE attribute in the METADATA
matches any SupCat in the StringMap and if it does then output the iCat value.
BUT I want to output only one match, i.e., if there is more than one match (as
in this case GB and ODD both match) I want only one of them.
I would also like it to be determinant which would be output given the ordering
in the METADATA and/or the StringMap.
I am able to write a transform which gets all of the matches but not only the
"first".
mike
(Embedded
image moved Steve Dahl <sdahl@xxxxxxxxxxx>
to file: 09/23/99 02:02 PM
pic25952.pcx)
To: Michael Teigman <michael.teigman@xxxxxxxxxxx>
cc: (bcc: Michael Teigman/HPG/US/Reuters)
Subject: Re: How Can You Exit an xsl:for-each Loop Prematurely?
Try something like this:
<xsl:for-each select="//Salesman/Orders/@Order[string(.) != ''][1]">
...output something...
</xsl:for-each/>
The first bracket should eliminate empty attributes, and the second should
restrict the search to the
first one only.
Michael Teigman wrote:
> 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
--
- Steve Dahl
sdahl@xxxxxxxxxxx
------------------------------------------------------------------------
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:
pic25952.pcx
Description: Binary data
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: How Can You Exit an xsl:for-eac, Dan Machak | Thread | Re: How Can You Exit an xsl:for-eac, Dan Machak |
| Two implementations, different resu, Terris | Date | Re: Can solve the N-queens - but ca, Paul Rabin |
| Month |