Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 13th, 2004, 06:26 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Grouping and Filtering

I am currently using xsl keys in my xsl document, to group child nodes
under
parent nodes. This is being run against an ADO recordset so my key looks
something like this :

<xsl:key name="rows-by-parent" match="z:row" use="@Parent_ID" />

My hierarchy can go several levels deep (about 10 levels are currently
supported). If any one of the children (n levels deep) of a level 1
parent
node(@Parent_ID = 0), has a variable @Exclude_YN = 'P' or Exclude_YN = 'C',
then I wish to display a text message next to that Parent Node, in my HTML
document.

I don't know how to apply the filter to child nodes n levels deep in the
hierarchy using an xsl:key. I am using keys to group currently.


thanx.

mike


 
Old October 13th, 2004, 11:12 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the following xml is a good example of your document:

<z:foo xmlns:z="foo">
    <z:row ID="1" Parent_ID="0"></z:row>
    <z:row ID="2" Parent_ID="0"></z:row>
    <z:row ID="3" Parent_ID="1"></z:row>
    <z:row ID="4" Parent_ID="3" Exclude_YN = 'P'></z:row>
    <z:row ID="5" Parent_ID="2" Exclude_YN = 'C'></z:row>
</z:foo>

the following xsl produces the output:

Row Id: 1 contains P
Row Id: 2 contains C

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

         <xsl:key name="rows-by-parent" match="z:row" use="@Parent_ID" />

       <xsl:template match="/">

               <xsl:apply-templates select="z:foo/z:row[@Parent_ID='0']" />

       </xsl:template>

       <xsl:template match="z:row[@Parent_ID='0']">
               Row Id: <xsl:value-of select="@ID" />

               <xsl:apply-templates select="key('rows-by-parent', @ID)" />
            <br />
       </xsl:template>

       <xsl:template match="z:row[@Parent_ID!='0']">
               <xsl:choose>
                   <xsl:when test="@Exclude_YN='P'"> contains P </xsl:when>
                   <xsl:when test="@Exclude_YN='C'"> contains C </xsl:when>
               </xsl:choose>

              <xsl:apply-templates select="key('rows-by-parent', @ID)" />

       </xsl:template>

</xsl:stylesheet>

Hope that helps!

Bryan







Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping in xsl saurabh_inblore XSLT 0 January 12th, 2007 12:37 PM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
xsl grouping aiyer0912 XSLT 9 November 7th, 2006 12:13 PM
Grouping and Filtering: With parameter variables? asearle XSLT 3 September 4th, 2006 09:01 AM
Section Grouping (XSL Newbie!) vjlomas XSLT 1 February 4th, 2005 04:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.