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 June 3rd, 2014, 04:25 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I get one result back instead of multiple results?

I have a xml document which has 2 Service information elements. When I run my xsl , I only want to see one Deleted notification
<NotificationEvent>Deleted</NofiticationEvent> instead of two.

Here is the result with two NotificationEvents.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<NotificationEvent xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" notificationType="ProtectionOrderService" elementKey="1200" servedByWord="KL0820700" servedByText="Grove Police Department" dateServed="03/25/2014" timeServed="10:00 AM" howServedWord="PERSON" howServedText="In-Person" whoWasServedInternalId="704607705">Deleted</NotificationEvent>

<NotificationEvent xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" notificationType="ProtectionOrderService" elementKey="1200" servedByWord="GN0170000" servedByText="County Sheriff's Office" dateServed="03/24/2014" timeServed="8:00 PM" howServedWord="SHORTFORM" howServedText="Short Form" whoWasServedInternalId="704607705">Deleted</NotificationEvent>
XSL should check if the <ServiceInfo> element has an Op="A" or "E" or "D". If it finds one or more of these, the output should be only one message. In my case I am getting two messages because there are two elements with <ServiceInfo Op="D">

Here is my xml
Code:
<ServicesInfo>
          <ServiceInfo Op="D">	     						     <ServedBy Op="D" Word="KL0820700">Grove Police Department</ServedBy>
	 <DateServed Op="D">03/25/2014</DateServed>
	 <TimeServed Op="D">10:00 AM</TimeServed>
	 <HowServed Op="D" Word="PERSON">In-Person</HowServed>
	 <WhoWasServed Op="D" InternalPartyID="704607705"/>
	 </ServiceInfo>
 <ServiceInfo Op="D">
   <ServedBy Op="D" Word="GN0170000">County Sheriff's Office</ServedBy>
   <DateServed Op="D">03/24/2014</DateServed>
   <TimeServed Op="D">8:00 PM</TimeServed>
   <HowServed Op="D" Word="SHORTFORM">Short Form</HowServed>
   <WhoWasServed Op="D" InternalPartyID="704607705"/>
    </ServiceInfo>
</ServicesInfo>
Here is my XSLT Selector. How do I change the <xsl:for-each select
Code:
<xsl:template name="ProtectionOrderService">
<xsl:if test="Integration/ControlPoint='SAVE-PROTECTION-ORDER'">
<!-- Check for Added -->
  <xsl:if test="Integration/Case/CaseType/@Word='DMA'">
    <xsl:if test="Integration/ControlPoint/@UserID!='IntegrationAdmin'">
	
<xsl:for-each select="Integration/Case/ProtectionOrders/ProtectionOrder[(@Op='E') and  ((Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDCOR') or (Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDOFC'))]/KLProtectionOrderAdditional/ServicesInfo/ServiceInfo[(@Op='A') or (@Op='E') or (@Op='D')]">


<NotificationEvent notificationType="ProtectionOrderService">
<xsl:attribute name="elementKey"><xsl:value-of select="../../@InternalProtectionOrderID"/></xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="../../../@InternalProtectionOrderID"/></xsl:attribute>
<xsl:attribute name="servedByWord"><xsl:value-of select="ServedBy/@Word"/></xsl:attribute>
<xsl:attribute name="servedByText"><xsl:value-of select="ServedBy"/></xsl:attribute>
<xsl:attribute name="dateServed"><xsl:value-of select="DateServed"/></xsl:attribute>
<xsl:attribute name="timeServed"><xsl:value-of select="TimeServed"/></xsl:attribute>
<xsl:attribute name="howServedWord"><xsl:value-of select="HowServed/@Word"/></xsl:attribute>
<xsl:attribute name="howServedText"><xsl:value-of select="HowServed"/></xsl:attribute>
<xsl:attribute name="whoWasServedInternalId"><xsl:value-of select="WhoWasServed/@InternalPartyID"/></xsl:attribute>
<xsl:choose>
<xsl:when test="@Op='A'">Added</xsl:when>
<xsl:when test="@Op='E'">Modified</xsl:when>
<xsl:when test="@Op='D'">Deleted</xsl:when>
</xsl:choose>
</NotificationEvent>
</xsl:for-each>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
This is the part I need to change but I am not sure how. I think I need to add a WHERE clause and check if there is "A" or "E" or "D". If one is found even if there are several of each ("A", "E", "D"), the out put should only be one message.
Code:
<xsl:for-each select="Integration/Case/ProtectionOrders/ProtectionOrder[(@Op='E') and  ((Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDCOR') or (Statuses/Status[(Current='true') and (not(@Op))]/Type/@Word='SIGNJUDOFC'))]/KLProtectionOrderAdditional/ServicesInfo/ServiceInfo[(@Op='A') or (@Op='E') or (@Op='D')]">

Last edited by winkimjr2; June 3rd, 2014 at 04:29 PM.. Reason: Formatting
 
Old June 3rd, 2014, 05:36 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

To get the first ServiceInfo matching the predicate then just use "ServiceInfo[(@Op='A') or (@Op='E') or (@Op='D')][1]"

Also, learn to use attribute value types, much simpler to read and understand I find
, e.g:

<NotificationEvent elementKey="{../../@InternalProtectionOrderID}" ...>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 4th, 2014, 09:37 AM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default

Thanks Sam for the response and a link to a great article. What I am trying to do with my <xsl:for-each select=...> statement is to generate only one notification. For example if the user delete a service and add another service, there will be only one notification for the added service. I am not sure how to use the where clause in the <xsl:for-each select=...
 
Old June 4th, 2014, 09:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sounds as if you have a "duplicates elimination" problem, also known as a "grouping" problem. It's not clear to me whether you are on XSLT 1.0 or 2.0 - grouping is much easier in 2.0 using the xsl:for-each-group instruction. If you need to do it in 1.0, search for "grouping" or "Muenchian grouping"; it's tricky to master but easy once you work out what's going on.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 4th, 2014, 12:07 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
Sounds as if you have a "duplicates elimination" problem, also known as a "grouping" problem. It's not clear to me whether you are on XSLT 1.0 or 2.0 - grouping is much easier in 2.0 using the xsl:for-each-group instruction. If you need to do it in 1.0, search for "grouping" or "Muenchian grouping"; it's tricky to master but easy once you work out what's going on.
I have Altova Spy 2014 and in this code I am using XSLT 1.0. I can however change it to 2.0. On the interim, I will do as you advice i.e. grouping. Thanks for your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to manage multiple checkbox result manius Visual Basic 2005 Basics 4 January 2nd, 2008 10:46 AM
xsl template, next result or next 10 results ge_or_gi XSLT 8 April 2nd, 2007 07:01 AM
Send code to server and getto=ing back result topshed Classic ASP Professional 1 January 30th, 2006 12:56 AM
how to search on multiple sites and showing result cyberviral Classic ASP Basics 0 March 23rd, 2004 09:08 AM
Displaying Multiple Results webasp1 Classic ASP Databases 2 July 24th, 2003 12:41 PM





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