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

Re:

Subject: Re:
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 15 Apr 2002 15:13:45 +0100
 Re:
Hi Biray,

> I need to select the first occurance of values in attributes of
> elements and show them in different color. i.e. for the following
> example lets say first occurance of "Mr.White", "Mr.Green",
> "Mr.Yellow", "Mr.Red" should be shown as red color and repeating
> ocuurances of these values should be shown as black color.

The most efficient way to tackle this problem is to use a key to index
all the Content elements by their ContentText attribute, as follows:

<xsl:key name="content" match="Content" use="@ContentText" />

You can then call the key using the key() function to get all the
Content elements with the same value for their ContentText attribute.
For example, to get all the Content elements with 'Mr.White' in their
ContentText attribute, you could use:

  key('content', 'Mr.White')

You can then identify which is the first of these nodes using a
positional predicate to pick the first one:

  key('content', 'Mr.White')[1]

So, given that you're currently on a Content element, you can find the
first Content element with that value for the ContentText attribute
using:

  key('content', @ContentText)[1]

You can then see if the Content element you're on is the same as this
Content element by comparing their generated IDs:

  generate-id() = generate-id(key('content', @ContentText)[1])

or using set logic:

  count(.|key('content', @ContentText)[1]) = 1

If they're the same, you want red; if they're different, you want
black, so you could use, for example:

<xsl:template match="Content">
  <div>
    <xsl:attribute name="style">
      <xsl:text>color: </xsl:color>
      <xsl:choose>
        <xsl:when test="count(.|key('content', @ContentText)[1]) = 1">
          <xsl:text>red</xsl:text>
        </xsl:when>
        <xsl:otherwise>black</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
    <xsl:value-of select="@ContentText" />
  </div>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • [no subject]
    • Biray Giray - Mon, 15 Apr 2002 09:20:26 -0400 (EDT)
      • Jeni Tennison - Mon, 15 Apr 2002 10:08:21 -0400 (EDT) <=

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.