Subject: RE: Filter by multiple nodes w/ different values
From: Emmanuel Begue <eb@xxxxxxxxxx>
Date: Wed, 20 Jan 2010 17:13:46 +0100
|
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>
>
>
> Thanks for your help!
> _______________________________
> Sharon Goldner Harris
> Knowledge Management Evangelist
> Ultimate Software Group
> 704-660-6482
>
> Confidentiality Note: This e-mail message and any attachments to it are
> intended only for the named recipients and may contain legally privileged
> and/or confidential information. If you are not one of the intended
> recipients, do not duplicate or forward this e-mail message.
|