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

RE: distinct values by xslt

Subject: RE: distinct values by xslt
From: "JS Rawat" <jrawat@xxxxxxxxxxxxxx>
Date: Thu, 19 May 2011 12:35:15 +0530
RE:  distinct values by xslt
Hi Wendell,
I am using XSLT 2.0. will you please integrate it into below xslt!!!
 

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx] 
Sent: Wednesday, May 18, 2011 9:51 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  distinct values by xslt

Hi,

As I understand it, this isn't really a "distinct values" problem, but
rather a problem of discriminating between nodes within sets of nodes, all
of which have the same values associated with them. The first question here
is whether this must be XSLT 1.0, or whether XSLT 2.0 can be used.

If you want to determine whether a node is the first node in the document
with a specific value associated with it (such as the first 'link' element
with a given @rid value), a good solution can be to use a
key:

<xsl:key name="link-by-rid" match="link" use="@rid"/>

Once this key is set up, you can examine any $link (where $link is a single
'link' element):

XSLT 1.0:

  generate-id($link) = generate-id(key('link-by-rid',$link/@rid)[1])

XSLT 2.0:

  $link is key('link-by-rid',$link/@rid)[1]

This method will also be faster, typically, than using the preceding:: axis.

You can do the same thing without a key, but that will often be slower too
(it depends on the processor):

XSLT 1.0:

  generate-id($link) = generate-id((//link[@rid=$link/@rid])[1])

XSLT 2.0:

  $link is (//link[@rid=$link/@rid])[1]

The extra parentheses are necessary here, unless you opt to use the
descendant:: axis instead of //.

Cheers,
Wendell

On 5/18/2011 11:36 AM, Syd Bauman wrote:
> I'm afraid this is too confusing to delve into right now, but I'm 
> wondering about the test for a preceding link (line 07). Do you 
> imagine that it is testing from a current node of a<link>  that has 
> type=figure? It's not -- the current node is still the<p>  that fired 
> the whole template to match.
>
> 01.<xsl:template match="p">
> 02.<p class="Para_indented">
> 03.<xsl:apply-templates/>
> 04.</p>
> 05.<xsl:if test="link[@type='figure']"> 06.<xsl:variable name="figid" 
> select="link[@type='figure']/@rid"/>
> 07.<xsl:if test="not(preceding::link[@type='figure'][@rid=$figid])">
> 08.<xsl:apply-templates select="//object[@id=$figid]"/> 09.</xsl:if> 
> 10.</xsl:if> 11.<xsl:if test="link[@type='table']"> 12.<xsl:variable 
> name="tableid" select="link[@type='table']/@rid"/>
> 13.<xsl:if test="not(preceding::link[@type='table'][@rid=$tableid])">
> 14.<xsl:apply-templates select="//object[@id=$tableid]"/> 15.</xsl:if> 
> 16.</xsl:if> 17.</xsl:template>
>
> Also I wonder if you are doing what you really want in line 06. The 
> variable figid is getting set to the sequence of all @rid values of 
> <link>  children of the current<p>  that match the criteria (have a 
> type= of 'figure'). For the test data, that means the string value of 
> figid is "f2 f3 f1".
>
>> Anyone have any idea about to find out distinct attribute value by 
>> xslt. Figure 2 and Figure 3 are getting deleted by the logic provided 
>> by me as shown in the below XSLT. Below are the require things
>>
>> XSLT
>> <xsl:template match="p">
>> <p class="Para_indented">
>>   <xsl:apply-templates/>
>> </p>
>>    <xsl:if test="link[@type='figure']">
>>     <xsl:variable name="figid" select="link[@type='figure']/@rid"/>
>>     <xsl:if test="not(preceding::link[@type='figure'][@rid=$figid])">
>>      <xsl:apply-templates select="//object[@id=$figid]"/>
>>     </xsl:if>
>>    </xsl:if>
>>    <xsl:if test="link[@type='table']">
>>     <xsl:variable name="tableid" select="link[@type='table']/@rid"/>
>>     <xsl:if test="not(preceding::link[@type='table'][@rid=$tableid])">
>>      <xsl:apply-templates select="//object[@id=$tableid]"/>
>>     </xsl:if>
>>    </xsl:if>
>> </xsl:template>
>>
>>
>> Input
>> <p>First One of the primary goals (<link rid="f1" type="figure">Fig.
>> 1</link>).</p>
>> <p>second (see<link rid="f2" type="figure">Fig. 2</link>) and thos 
>> and <link rid="f3" type="figure">Fig. 3</link>). supporting the 
>> prediction that these species accelerate their development at the 
>> expense of growth (<link rid="f1" type="figure">Fig. 1</link>).</p>
>>
>>
>> Required OUTPUT
>> <p class="Para_Indented">First One of the primary goals (<a
class="figcit"
>> href="#fig1">Fig. 1</a>).</p>
>> <div class="divFigure">
>>   <table class="Figure" width="100%" align="center" border="0" id="fig1">
>>   </table>
>> </div>
>> <p class="Para_Indented">second (see<a class="figcit" href="#fig2">Fig.
>> 2</a>) and thos and<a class="figcit" href="#fig3">Fig. 3</a>). 
>> supporting the prediction that these species accelerate their 
>> development at the expense of growth (<a class="figcit" 
>> href="#fig1">Fig. 1</a>).</p> <div class="divFigure">
>>   <table class="Figure" width="100%" align="center" border="0" id="fig2">
>>   </table>
>> </div>
>> <div class="divFigure">
>>   <table class="Figure" width="100%" align="center" border="0" id="fig3">
>>   </table>
>> </div>
>>
>> CURRENT OUTPUT
>> <p class="Para_Indented">First One of the primary goals (<a
class="figcit"
>> href="#fig1">Fig. 1</a>).</p>
>> <div class="divFigure">
>>   <table class="Figure" width="100%" align="center" border="0" id="fig1">
>>   </table>
>> </div>
>> <p class="Para_Indented">second (see<a class="figcit" href="#fig2">Fig.
>> 2</a>) and thos and<a class="figcit" href="#fig3">Fig. 3</a>). 
>> supporting the prediction that these species accelerate their 
>> development at the expense of growth (<a class="figcit" 
>> href="#fig1">Fig. 1</a>).</p>


--
======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

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.