Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: selecting nested distinct records -- Help

From: "Marrow" <m--a-r-r-o-w@--------------------.--->
To: NULL
Date: 10/3/2004 11:40:00 PM
Hi,

Using the Muenchian technique, you would need to find the distinct vchAdmin
values, then use another key to find the distinct vchRoots withing each
vchAdmin - something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="kDistinctAdmins" match="field[@name = 'vchAdmin']" use="."/>
<xsl:key name="kDistinctRootsPerAdmin" match="record"
use="concat(field[@name = 'vchAdmin'],'|',field[@name = 'vchRoot'])"/>

<xsl:template match="resultset">
  <resultset>
    <!-- find distinct admins -->
    <xsl:apply-templates select="record/field[@name =
'vchAdmin'][generate-id() = generate-id(key('kDistinctAdmins',.))]"/>
  </resultset>
</xsl:template>

<!-- this template will catch the distinct vchAdmin values -->
<xsl:template match="field">
  <record>
    <vchAdmin>
      <xsl:value-of select="."/>
    </vchAdmin>
    <iDistinctRoots>
      <!-- count distinct vchRoot's within this vchAdmin -->
      <xsl:value-of
select="count(key('kDistinctAdmins',.)/parent::record[generate-id() =
generate-id(key('kDistinctRootsPerAdmin',concat(field[@name =
'vchAdmin'],'|',field[@name = 'vchRoot'])))])"/>
    </iDistinctRoots>
  </record>
</xsl:template>
</xsl:stylesheet>


HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


"Lana" <svet_lana_p@h...> wrote in message
news:baabf53d.0410031101.18c4d631@p......
> I'm just learning XSLT and am currently stuck trying to solve the
> following problem.
>
> My XML looks like this:
>
> <resultset>
> - <record>
>   <field name="vchAdmin">XXX</field>
>   <field name="vchRoot">1</field>
>   </record>
> - <record>
>   <field name="vchAdmin">YYY</field>
>   <field name="vchRoot">1</field>
>   </record>
> - <record>
>   <field name="vchAdmin">YYY</field>
>   <field name="vchRoot">2</field>
>   </record>
> - <record>
>   <field name="vchAdmin">YYY</field>
>   <field name="vchRoot">2</field>
>   </record>
> - <record>
>   <field name="vchAdmin">ZZZ</field>
>   <field name="vchRoot">1</field>
>   </record>
> - <record>
>   <field name="vchAdmin">ZZZ</field>
>   <field name="vchRoot">1</field>
>   </record>
> <resultset>
>
> What I need to achieve is to count # of DISTINCT vchRoot's PER
> vchAdmin and place that into a different XML format.
>
> In this case, my output has to be:
>
> <resultset>
>   <record>
>   <vchAdmin>XXX</vchAdmin>
>   <iDistinctRoots>1</iDistinctRoots>
>   </record>
>   <record>
>   <vchAdmin>YYY</vchAdmin>
>   <iDistinctRoots>2</iDistinctRoots>
>   </record>
>   <record>
>   <vchAdmin>ZZZ</vchAdmin>
>   <iDistinctRoots>1</iDistinctRoots>
>   </record>
> </resultset>
>
> I've tried using nested keys to first get distinct vchAdmin's and then
> get and count distinct vchRoots for each vchAdmin but nothing seems to
> work.
>
> Please help?
> Thank you in advance!!
>
> XSLT Newby




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent