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

Re: Fwd: Filter by multiple nodes w/ different values

Subject: Re: Fwd: Filter by multiple nodes w/ different values
From: Sharon_Harris@xxxxxxxxxxxxxxxxxxxx
Date: Thu, 21 Jan 2010 05:41:27 -0500
Re: Fwd:  Filter by multiple nodes w/ different values
Thank you so much Emmanuel. Your solution not only worked like a charm, but
was extremely elegant as well!

Sharon


From: Emmanuel Begue <eb@xxxxxxxxxx>
Date: Wed, Jan 20, 2010 at 11:13 AM
Subject: RE:  Filter by multiple nodes w/ different values
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx


Hello,

If you want to process Row elements that contain a Role element
with a value of 'Manager' and a Portal_Only element with a value
of 'Yes', then you would need a template that matches those:

<xsl:template match="Row[Role='Manager' and Portal_Only='Yes']">
 ... do something...
</xsl:template>

Also:
- if there are more than one Row, then Row cannot be the root
 (you're using /Row/some_node a couple times in your
 stylesheet where it seems you meant /Root/Row/some_node)
- quotes make strings
- dollar signs prefix variables
- variables need to be declared before they're used

Hope this helps.
Regards,
EB


> -----Original Message-----
> From: Sharon_Harris@xxxxxxxxxxxxxxxxxxxx
> [mailto:Sharon_Harris@xxxxxxxxxxxxxxxxxxxx]
> Sent: Wednesday, January 20, 2010 4:27 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Filter by multiple nodes w/ different values
>
>
>
> Hi,
>
> I am trying to pull data based on the values for different nodes. These
> values will be different as well. I have tried using for-each w/ multiple
> conditions and then using a value-of statement but that only produced
> "true" instead of the data (the conditions had been met). I tried using
an
> if statement w/ multiple conditions and the using apply-templates but
once
> the condition was met, then all data was pulled. I tried using multiple
> keys but only 1 key was executed.
>
> Here's the XML snippet. I want to output only Row data if Portal_Only=Yes
> and Role=Manager. I am outputting the data into a table and there
> will be a
> table for each Role value (such as Manager, Employee, etc.) and each
table
> will only contain data for that Role value and only if Portal_Only=Yes.
>
> <Row>
>             <Role>Manager</Role>
>             <Process>Manage my employee's general employee information</
> Process>
>             <Where_can_I>Add/Change an employee's union contract dates</
> Where_can_I>
>             <Where_can_I_do_this_in_the_backoffice>File, Setup, Codes,
> Labor Unions</Where_can_I_do_this_in_the_backoffice>
>             <Where_can_I_do_this_on_the_Portal>NA</
> Where_can_I_do_this_on_the_Portal>
>             <Portal_Only>No</Portal_Only>
>             <Backoffice_Only>Yes</Backoffice_Only>
> </Row>
>
> <Row>
>             <Role>Employee</Role>
>             <Process>Manage my personal information</Process>
>             <Where_can_I>Select a payroll related indicator</Where_can_I>
>             <Where_can_I_do_this_in_the_backoffice>Employee, View/Edit,
> Status</Where_can_I_do_this_in_the_backoffice>
>             <Where_can_I_do_this_on_the_Portal>My Team, My Employees,
> select an employee, Personal, Status/Key Dates, Status History</
> Where_can_I_do_this_on_the_Portal>
>             <Portal_Only>Yes</Portal_Only>
>       </Row>
>       <Row>
>             <Role>Manager</Role>
>             <Process>Manage my employee's general employee information</
> Process>
>             <Where_can_I>iew/Add/Change/Delete an employee's awards and
> recognition information</Where_can_I>
>             <Where_can_I_do_this_in_the_backoffice>Employee, View/Edit,
> Status</Where_can_I_do_this_in_the_backoffice>
>             <Where_can_I_do_this_on_the_Portal>My Team, My Employees,
> select an employee, Personal, Status/Key Dates, Status History</
> Where_can_I_do_this_on_the_Portal>
>             <Portal_Only>Yes</Portal_Only>
>       </Row>
>       <Row>
>             <Role>Manager</Role>
>             <Process>Manage my employee's career development
information</
> Process>
>             <Where_can_I>Take notes on an employee's current status and
> status history</Where_can_I>
>             <Where_can_I_do_this_in_the_backoffice>Employee, View/Edit,
> Status</Where_can_I_do_this_in_the_backoffice>
>             <Where_can_I_do_this_on_the_Portal>NA</
> Where_can_I_do_this_on_the_Portal>
>             <Portal_Only>Yes</Portal_Only>
>             <Backoffice_Only>No</Backoffice_Only>
>       </Row>
>
>
> Here's the XSL snippet. This template creates the table and is
> called later
> on in the stylesheet. I am creating multiple HTML files from 1 XML file
as
> I not only want to create an output containing tables for each Role value
> if Portal_Only=Yes but I also create separate output/HTML files per Role
> value that contain all the data for that Role value though this latter
> output I have succeeded in creating. At the point I am creating the HTML
> file for former output is when I call the template below.
>
> <xsl:template name="TasksProcessesWebTable">
>             <xsl:if test="'/Row/Portal_Only[contains(., $Yes)]' and
> 'Root/Row/Role[contains(., $Manager)]'">
>                         <h1>
>                               <a name="contents">
>                                     <xsl:text>Manager</xsl:text>
>                               </a>
>                         </h1>
>                   </xsl:if>
>
>             <xsl:if test="'/Row/Portal_Only[contains(., $Yes)]' and
> 'Root/Row/Role[contains(., $Employee)]'">
>                   <h1>
>                         <a name="contents">
>                               <xsl:text>Employee</xsl:text>
>                         </a>
>                   </h1>
>             </xsl:if>
>             <xsl:call-template name="SortTableNote"/>
>             <table class="sortable" width="95%" border="1"
cellpadding="5"
> id="sortabletableManager">
>                   <xsl:call-template name="TableHeaders"/>
>
>                   <!--START LISTING OF CODE THAT HAS BEEN TRIED-->
>
>                   <!--This produced "Not a node item" error-->
>                   <xsl:for-each
> select="'/Row/Portal_Only[text()=$Yes]' and
> 'Root/Row/Role[text()=$Manager]'">
>                   <xsl:apply-templates/>
>                   </xsl:for-each>
>
>                   <!--This produced "True" to be outputted instead of
data
> -->
>                   <xsl:for-each
> select="'/Row/Portal_Only[text()=$Yes]' and
> 'Root/Row/Role[text()=$Manager]'">
>                   <xsl:value-of select="."/>
>                   </xsl:for-each>
>
>                   <!--This produced all data for Role=Manager regardless
> whether Portal_Only=Yes-->
>                   <xsl:if test="'/Row/Portal_Only[text()=$Yes]' and
> 'Root/Row/Role[text()=$Manager]'">
>                   <xsl:apply-templates select="key('Role', $Manager) |
key
> ('PortalOnly', $Yes)"/>
>                   </xsl:if>
>
>                   <!--This produced all data for Role=Manager regardless
> whether Portal_Only=Yes-->
>                   <xsl:if test="'/Row/Portal_Only[text()=$Yes]' and
> 'Root/Row/Role[text()=$Manager]'">
>                   <xsl:apply-templates/>
>                   </xsl:if>
>
>                   <!--END LISTING OF CODE THAT HAS BEEN TRIED-->
>
>             </table>
>             <xsl:call-template name="BackToTop"/>
>       </xsl:template>

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.