Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - XSLT: selecting nested distinct records -- Help >Thread Next - Re: selecting nested distinct records -- Help Re: selecting nested distinct records -- HelpTo: 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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
