Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 7th, 2019, 01:28 PM
Authorized User
Points: 442, Level: 7
Points: 442, Level: 7 Points: 442, Level: 7 Points: 442, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 96
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..
Reply With Quote
  #2 (permalink)  
Old February 7th, 2019, 01:57 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
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
Authorized User
Points: 442, Level: 7
Points: 442, Level: 7 Points: 442, Level: 7 Points: 442, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 96
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>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.