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

Re: First Occurance Problem

Subject: Re: First Occurance Problem
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 24 Mar 2003 17:12:45 +0000
first occurance string
Hi Deepak,

> I have the following template
>
> <agg1>
>    <agg2>             <----Can repeat 1 to N times
>       <tag1></tag1>   <----Both tag1 and tag2 can be empty
>       <tag2></tag2>
>    </agg2>
> </agg1>
>
> Problem:
>
> I want to return a xml with the following template
>
> <agg1>
>    <agg2>             <----Can occur only once
>       <tagx></tagx>   <----tag1 will have the value from the first
>                            populated occurance of tag1 in the source xml
>    </agg2>
> </agg1>

You can locate the value of the first populated occurrence of <tag1>
with:

  (/agg1/agg2/tag1[string(.)])[1]

The [string(.)] predicate tests whether the <tag1> element has a
string value or not. The brackets ensure that the [1] predicate
applies to the position of the <tag1> element within all the <tag1>
elements in the document rather than just those found within a
particular <agg2> element. You can therefore build your result as:

<xsl:template match="agg1">
  <agg1>
    <agg2>
      <tagx>
        <xsl:value-of select="(agg2/tag1[string(.)])[1]" />
      </tagx>
    </agg2>
  </agg1>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.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.