INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to I check for all Protection orders based on condition?
2

How to I check for all Protection orders based on condition?

How to I check for all Protection orders based on condition?

(OP)
My template is correctly displaying output when any CasePartyName has an Op='E'.
It is also correctly displaying output when any CaseParty/ObservedRace has an Op='E' or CaseParty/ObeservedEthnicity has an Op='E' and Connection/@Word='RSP'

Current output

CODE --> xml

<NotificationEvent notificationType="CasePartyUpdates" >CasePartyUpdate</NotificationEvent> 

Now I would like to add an attribute to the above output to display the ProtectionOrder number/s of any ProtectionOrder/s that have Status/Current="true" and Status/Type/@Word="SBJO or SBJOCOR".

Here is what the output based on my xml document should look like..

CODE --> xml

<NotificationEvent notificationType="CasePartyUpdates" activeSignedPoNumbers="1605923">CasePartyUpdate</NotificationEvent> 

If there were more qualified protectionorders, their numbers would be displayed as activeSignedPoNumber="1605923, 111, 078, 4532" etc.

I am stuck that is why I opted to get help.

My xml document

CODE --> xml

<Integration>
	<ControlPoint>SAVE-FAM-CASE</ControlPoint>
	<Case>
		<CaseCategory>FAM</CaseCategory>
		<CaseType Word="DMA">Domestic Abuse</CaseType>
		<CaseParty>
			<ObservedRace Word="W">White</ObservedRace>
			<ObservedEthnicity Word="NH">Non Hispanic</ObservedEthnicity>
			<Connection Word="PET">
			</Connection>
		</CaseParty>
		<CaseParty Op="E">
			<ObservedRace Op="E" Word="M">Multiracial</ObservedRace>
			<ObservedEthnicity Op="E" Word="R">Refused</ObservedEthnicity>
			<Connection Word="RSP">
			</Connection>
		</CaseParty>
		<ProtectionOrders>
			<ProtectionOrder InternalProtectionOrderID="11257">
				<ProtectionOrderNumber>1605921</ProtectionOrderNumber>
				<Statuses>
					<Status>
						<Current>true</Current>
						<Type Word="SUPERSEDED">Superseded</Type>
					</Status>
					<Status>
						<Current>false</Current>
						<Type Word="SBJOCOR">Corrected - Signed By Judicial Officer</Type>
					</Status>
				</Statuses>
			</ProtectionOrder>
			<ProtectionOrder InternalProtectionOrderID="11259">
				<ProtectionOrderNumber>1605923</ProtectionOrderNumber>
				<Statuses>
					<Status>
						<Current>true</Current>
						<Type Word="SBJOCOR">Corrected - Signed By Judicial Officer</Type>
					</Status>
					<Status>
						<Current>false</Current>
						<Type Word="SBJO">Signed By Judicial Officer</Type>
					</Status>
				</Statuses>
			</ProtectionOrder>
		</ProtectionOrders>
	</Case>
</Integration> 

Xslt template

CODE --> XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" >
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
			<xsl:call-template name="CasePartyUpdates"/>
	<xsl:template name="CasePartyUpdates">
		<xsl:if test="Integration/ControlPoint='SAVE-FAM-CASE'">
			<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
				<xsl:variable name="vActiveSignedPoNumbers">
					<!--Loop through each PO if current status is SBJO OR SBJOCOR add the PO number -->
				</xsl:variable>
				<xsl:if test="(string-length($vActiveSignedPoNumbers)>0)">
				<xsl:for-each select="Integration/Case">
						<xsl:choose>
							<xsl:when test="(count(CaseParty[((ObservedRace/@Op='E') or (ObservedEthnicity/@Op='E')) and (Connection/@Word='RSP')] )>0)">
								<NotificationEvent notificationType="CasePartyUpdates">
									<xsl:attribute name="activeSignedPoNumbers"><xsl:value-of select="$vActiveSignedPoNumbers"/></xsl:attribute>
									<xsl:text>CasePartyUpdate</xsl:text>
								</NotificationEvent>
							</xsl:when>
							<xsl:when test="(count(CaseParty[CasePartyName/@Op='E']) >0)">
								<NotificationEvent notificationType="CasePartyUpdates">
									<xsl:attribute name="activeSignedPoNumbers"><xsl:value-of select="$vActiveSignedPoNumbers"/></xsl:attribute>
									<xsl:text>CasePartyUpdate</xsl:text>
								</NotificationEvent>
							</xsl:when>
						</xsl:choose>
					</xsl:for-each>
				</xsl:if>
			</xsl:if>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet> 

RE: How to I check for all Protection orders based on condition?

Quote (momo2000)

CODE

<!--Loop through each PO if current status is SBJO OR SBJOCOR add the PO number --> 

Well, I see that you have version="3.0" on your xsl:stylesheet processing instruction, so forgive me for stepping back to good old version 1. I don't seem to have a version 3.0 XSLT processor available.

And in version 1, 'loop through' and 'add [concatenate]' are not terms that go well together. In version 1, one uses recursion.

In the XSL below, the xsl:variable processing instruction invokes a called template with a set of nodes that meet the criteria. The called template then uses recursion to go through all the nodes, building up the desired string.

CODE --> XSLT

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
			<xsl:call-template name="CasePartyUpdates"/>
	</xsl:template>
	<xsl:template name="CasePartyUpdates">
		<xsl:if test="Integration/ControlPoint='SAVE-FAM-CASE'">
			<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
				<xsl:variable name="vActiveSignedPoNumbers"><xsl:call-template name="listProtectionOrders">
																<xsl:with-param name="poNodes" select="Integration/Case/ProtectionOrders/ProtectionOrder[Statuses/Status/Type/@Word='SBJO' or Statuses/Status/Type/@Word='SBJOCOR']"/>
															</xsl:call-template></xsl:variable>
				<xsl:if test="(string-length($vActiveSignedPoNumbers)>0)">
				<xsl:for-each select="Integration/Case">
						<xsl:choose>
							<xsl:when test="(count(CaseParty[((ObservedRace/@Op='E') or (ObservedEthnicity/@Op='E')) and (Connection/@Word='RSP')] )>0)">
								<NotificationEvent notificationType="CasePartyUpdates">
									<xsl:attribute name="activeSignedPoNumbers"><xsl:value-of select="$vActiveSignedPoNumbers"/></xsl:attribute>
									<xsl:text>CasePartyUpdate</xsl:text>
								</NotificationEvent>
							</xsl:when>
							<xsl:when test="(count(CaseParty[CasePartyName/@Op='E']) >0)">
								<NotificationEvent notificationType="CasePartyUpdates">
									<xsl:attribute name="activeSignedPoNumbers"><xsl:value-of select="$vActiveSignedPoNumbers"/></xsl:attribute>
									<xsl:text>CasePartyUpdate</xsl:text>
								</NotificationEvent>
							</xsl:when>
						</xsl:choose>
					</xsl:for-each>
				</xsl:if>
			</xsl:if>
		</xsl:if>
	</xsl:template>

	<xsl:template name="listProtectionOrders">
	<xsl:param name="poNodes"/>
	<xsl:param name="poList" select="''"/>
	<xsl:choose>
	<xsl:when test="count($poNodes) = 0"><xsl:value-of select="$poList"/></xsl:when>
	<xsl:otherwise><xsl:call-template name="listProtectionOrders">
						<xsl:with-param name="poNodes" select="$poNodes[position() != 1]"/>
						<xsl:with-param name="poList"><xsl:value-of select="$poList"/><xsl:if test="string-length($poList) != 0">, </xsl:if><xsl:value-of select="$poNodes[1]/ProtectionOrderNumber"/></xsl:with-param>
					</xsl:call-template>
	</xsl:otherwise>
	</xsl:choose>
	</xsl:template>
</xsl:stylesheet> 

Tom Morrison
Hill Country Software

RE: How to I check for all Protection orders based on condition?

With a straightforward loop:

CODE --> XSLT

<xsl:variable name="vActiveSignedPoNumbers">
          <xsl:for-each select="Integration/Case/ProtectionOrders/ProtectionOrder[Statuses/Status[Current = 'true' and (Type/@Word = 'SBJO' or Type/@Word = 'SBJOCOR')]]">
            <xsl:if test="position() > 1"><xsl:text>, </xsl:text></xsl:if>
            <xsl:value-of select="ProtectionOrderNumber/text()"/>
          </xsl:for-each>
        </xsl:variable> 

RE: How to I check for all Protection orders based on condition?

atlopes,

Yes, in this situation a loop will work, but for the more general case recursion is the path to a solution. So, I guess because I feel comfortable with a recursion-based solution, I don't look for the special situations (such as this one) where a for-each will indeed work.

So, momo2000, you have two possibilities.

Tom Morrison
Hill Country Software

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close