Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old February 7th, 2019, 01:28 PM
Friend of Wrox
Points: 465, Level: 7
Points: 465, Level: 7 Points: 465, Level: 7 Points: 465, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I add a condition to Notification events?

I need help to add a condition for all notification events,. So that all notification events have the Hearing Type code must be ACT HearingType/@ Word = 'ACT' How do I do this in my xslt? I have reduced the xslt code.
When I run xlm code through xslt I am getting the following output which is wrong. The output is wrong because HearingType/@ Word = 'ACT' is not true. I should get no output at all.
Because <HearingType Op="A" Word="HGO">Hearing Officer Appointment</HearingType> output should be nothing.

Output which is wrong
Code:
<NotificationEvent notificationType="PrepareHearingDocument" elementState="New" elementName="Hearing" elementKey="252919460">HearingScheduled</NotificationEvent>
Output should only be shown when HearingType/@ Word = 'ACT' .

Xml document that I run through xslt

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Integration>
    <Case xmlns:user="http://tylertechnologies.com" InternalID="1625028718" ID="18477565">
	<Hearing xmlns:reslib="urn:reslib" ID="252919460" InternalHearingEventID="1851128069" Op="A">
		<HearingType Op="A" Word="HGO">Hearing Officer Appointment</HearingType><!--HearingType/@Word-->
		<Setting ID="32178675" InternalSettingID="1631575987" Date="01/22/2019" Op="A">
			<HearingDate Op="A">01/22/2019</HearingDate>
		</Setting>
	</Hearing>
   </Case>
<IntegrationConditions>
	<IntegrationCondition Word="HRGTRLSET" Description="HearingTrialSetting">
		<NotificationEvent notificationType="PrepareHearingDocument" elementState="New" elementName="Hearing" elementKey="252919460">HearingScheduled</NotificationEvent>
	</IntegrationCondition>
</IntegrationConditions>
</Integration>

My xlst code

Code:
<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml file:///Z:/Most%20things%20here/LeeAnn%20projects/Release%2064/HearingScheduled2.xml?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
      <xsl:template match="/">
	<xsl:apply-templates select="Integration/Case/Hearing"/>
     </xsl:template>
     <xsl:template match="Hearing">
  <!-- Set variable for Hearing ID -->
   <xsl:variable name="vID">
   <!--Get Hearing ID-->
   <xsl:value-of select="@ID"/>
	</xsl:variable>
	<xsl:choose>
		<xsl:when test="(@Op='A') and (HearingType/@Op='A')">
			<NotificationEvent notificationType="PrepareHearingDocument">
				<xsl:attribute name="elementState">New</xsl:attribute>
				<xsl:attribute name="elementName">Hearing</xsl:attribute>
				<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/><!--Get ID equal to ID from Hearing--></xsl:attribute>
				<xsl:text>HearingScheduled</xsl:text>
			</NotificationEvent>
		</xsl:when>
		<xsl:when test="(@Op='E') and (string-length(CancelledReason)!=0) and (CancelledReason/@Op='E')">
			<NotificationEvent notificationType="PrepareHearingDocument">
				<xsl:attribute name="elementState">New</xsl:attribute>
				<xsl:attribute name="elementName">Hearing</xsl:attribute>
				<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
				<xsl:text>HearingCancelled</xsl:text>
			</NotificationEvent>
		</xsl:when>
		<!--HearingCancelled-->
		<xsl:otherwise>
			<xsl:if test="(HearingType/@Op='E')">
				<NotificationEvent notificationType="PrepareHearingDocument">
					<xsl:attribute name="elementState">New</xsl:attribute>
					<xsl:attribute name="elementName">Hearing</xsl:attribute>
					<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
					<xsl:text>HearingModified</xsl:text>
				</NotificationEvent>
			</xsl:if>
			<!--HearingModified-->
			<xsl:for-each select="Setting[@Op='A']">
				<NotificationEvent notificationType="PrepareHearingDocument">
					<xsl:attribute name="elementState">New</xsl:attribute>
					<xsl:attribute name="elementName">Setting</xsl:attribute>
					<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
					<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
					<xsl:text>SettingScheduled</xsl:text>
				</NotificationEvent>
			</xsl:for-each>
			<!--SettingScheduled-->
		</xsl:otherwise>
	</xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Last edited by winkimjr2; February 7th, 2019 at 02:34 PM..
  #2 (permalink)  
Old February 7th, 2019, 01:57 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's very hard to help on this sort of question without seeing the source document; it also helps to show the current result you are getting and how this differs from the desired result.

You could almost certainly cut down the XSLT code so that it only includes the essence of the problem, removing extraneous detail.

Your XSLT code is also very verbose, which makes it more difficult to read . For example this:
Code:
<NotificationEvent notificationType="PrepareHearingDocument">
								<xsl:attribute name="elementState">Existing</xsl:attribute>
								<xsl:attribute name="elementName">Setting</xsl:attribute>
								<xsl:attribute name="elementKey"><xsl:value-of select="$vID"/></xsl:attribute>
								<xsl:attribute name="subElementKey"><xsl:value-of select="@ID"/></xsl:attribute>
could be reduced to this:

Code:
<NotificationEvent
   notificationType="PrepareHearingDocument"
   elementState="Existing"
   elementName="Setting"
   elementKey="{$vID}"
   subElementKey="{@ID}">
In addition there's a lot of common code between the branches of your xsl:choose that could perhaps be factored into a named template or attribute set - and perhaps the xsl:choose itself would be better structured as a set of template rules.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
winkimjr2 (February 7th, 2019)
  #3 (permalink)  
Old February 7th, 2019, 03:10 PM
Friend of Wrox
Points: 465, Level: 7
Points: 465, Level: 7 Points: 465, Level: 7 Points: 465, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default My solution

Here is what I have done at the top of my xslt code. I have tested many notifications and they are now either working (shows output when I expect output) or fails (shows no output when I expect none)

Code:
<xsl:template match="/">
	 <xsl:if test="/Integration/Case/Hearing/HearingType/@Word='ACT'">
	   <xsl:apply-templates select="Integration/Case/Hearing"/>
	</xsl:if>
	</xsl:template>


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add a condition in Visual studio to read xml? winkimjr2 XML 0 October 14th, 2014 12:24 PM
Chapter 2 - Notification not getting displayed shekhar.kotekar BOOK: Beginning Android Application Development 0 July 13th, 2011 03:34 AM
regarding login notification myself.panku ASP.NET 3.5 Professionals 0 July 27th, 2009 07:20 AM
add condition to COMMAND;ignore records for 3 min aubie1 Crystal Reports 0 July 17th, 2006 11:41 AM
Server notification to client deorecaido ASP.NET 2.0 Basics 0 March 7th, 2005 04:42 AM





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