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

Re: FIRST-OCCURENCE

Subject: Re: FIRST-OCCURENCE
From: naha@xxxxxxxxxx
Date: Tue, 05 Mar 2002 11:52:09 -0500 (EST)
kim possible naha
Quoting Kim Durand <vsd18@xxxxxxxxxxxxxx>:

[...]

> i run a for-each for colors and want to attach ***** to the text 
> of first occurence of the color with type = 'rude' and display the 
> subsequent color text in a normal way
> example,
> i want the display of the above xml file to be like ..
> *****red
> orange
> yellow


"rude" being one of those off-colors?   :-)
(sorry, couldn't resist)

Now that I've subjected you to the stupid pun I guess I owe 
you an answer.

Assuming you have a node set of the coloer elements you care about
in a variable named color-elements, then your for-each would look
like

    <xsl:for-each select="$color-elements">
      ...
    </xsl:for-each>

You already knew this but bear with me.

The first such color element whose type was 'rude' would be

    $color-elements[@type='rude'][1]

The function generate-id() returns a unique identifier for a node,
so we can determine if two nodes are the same node by seeing if
their generated ids are equal

    generate-id($node1) = generate-id($node2)

So, given the variable color-elements as described above

    <xsl:variable name="first-rude"
                  select="$color-elements[@type='rude'][1]"/>
    <xsl:for-each select="$color-elements">
        <xsl:if test="gener"ate-id(.) = generate-id($first-rude)">
            <xsl:text>*****</xsl:text>
        </xsl:if>
        <!-- output the color name.  normalize-space() removes
             leading and trailing whitespace. -->
        <xsl:value-of select="normalize-space(.)"/>
    </xsl:for-each>

I've not tried this and I may be a bit rusty, but it will atleast
outline how to do this.



 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.