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 do I add exception to my xslt code

How do I add exception to my xslt code

(OP)
I had this question posted but since I had to edit that question after an answer was provided, I think the best thing to do is posting a new question instead.
I have 4 TransactionTypeText being handled by xslt code which include TransactionTypeText='Charge', TransactionTypeText='Payment', TransactionTypeText='Credit', TransactionTypeText='Disbursement'.
The problem is that, this code is not handling other types (TransactionTypeText) that are not one of the the 4 types.
When I try TransactionTypeText='Adjustment', I am getting an error Unknown transaction type Adjustment because I have an exception in my xslt code to handle TransactionTypeText when it is of type other than the 4.

So I would like to modify my code so that it can handle all types of TransactionTypeText.
The requirement is that, to handle (other) TransactionTypeText that are not of type Charge, Credit, Disbursement, Payment, use the following condition:
For TransactionTypeText that are not Charge; Payment; Credit, and Disbursement get amount that is not equal to zero from any of the amount elements. This is because amount can be in any element.

Note: Unlike the 4 types, other types can have amount in any element. The amount for Charge is in ChargeAmount element, amount for Payment is in PaymentAmount element, amount for Disbursement is in DisbursementAmount element, amount for Credit is in CreditAmount. This is not the case for other tpes. So, for other types, I need to get amount from any element that has amount that is great than zero.

Note: For each of the other types, only one of the amount elements can have amount greater than zero. If there is more than one amount element with amount that is greater than zero, add exception with exception text "Transaction has more than one amount type"

Currently I am only handling (exception) when the TransactionTypeText is not one of the 4 (Charge, Payment, Credit, Disbursement

This is the specific are of xslt I need to modify

CODE --> xslt

<xsl:choose>
  <xsl:when test="../TransactionTypeText='Charge'">
    <xsl:value-of select="mscef:formatCurrency(string(ChargeAmount))"/>
  </xsl:when>
  <xsl:when test="../TransactionTypeText='Payment'">
    <xsl:value-of select="mscef:formatCurrency(string(PaymentAmount))"/>
  </xsl:when>
  <xsl:when test="../TransactionTypeText='Credit'">
    <xsl:value-of select="mscef:formatCurrency(string(CreditAmount))"/>
  </xsl:when>
  <xsl:when test="../TransactionTypeText='Disbursement'">
    <xsl:value-of select="mscef:formatCurrency(string(DisbursementAmount))"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:message terminate="yes">Unknown transaction type. <xsl:value-of select="../TransactionTypeText"/>
    </xsl:message>
  </xsl:otherwise>
</xsl:choose> 

Expected output

CODE --> xml

<FinancialDetail>
	<FinancialTransaction>
		<TransactionID>1639560336</TransactionID>
		<TransactionTypeText>Charge</TransactionTypeText>
		<TransactionDate>2016-07-11</TransactionDate>
		<TransactionFeeDetail>
			<FeeDetailID>1650110685</FeeDetailID>
			<FeeDetailFeeCodeText code="REST">Restitution</FeeDetailFeeCodeText>
			<FeeDetailFeeAmount>500</FeeDetailFeeAmount>
		</TransactionFeeDetail>
		<TransactionCommentText/>
		<TransactionPaymentCreditTypeText/>
	</FinancialTransaction>
	<FinancialTransaction>
		<TransactionID>1639560337</TransactionID>
		<TransactionTypeText>Adjustment</TransactionTypeText>
		<TransactionDate>2016-07-11</TransactionDate>
		<TransactionFeeDetail>
			<FeeDetailID>1650110685</FeeDetailID>
			<FeeDetailFeeCodeText code="REST">Restitution</FeeDetailFeeCodeText>
			<FeeDetailFeeAmount>-500</FeeDetailFeeAmount>
		</TransactionFeeDetail>
		<TransactionCommentText>Testing</TransactionCommentText>
		<TransactionPaymentCreditTypeText/>
	</FinancialTransaction>
</FinancialDetail> 

xslt stylesheet

CODE --> xslt

<xsl:stylesheet version="1.0" xmlns="http://www.courts.state.mn.us/CourtXML/3" xmlns:msc="http://www.courts.state.mn.us/CourtXML/3" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="mscef msxsl msc">
	<xsl:output method="xml" encoding="UTF-8"/>
	<xsl:template name="FinancialDetailType">
		<xsl:for-each select="ancestor::Integration/FinancialDetail/Transaction[count(TransactionFeeDetail[FeeDetailFeeCode='REST'])>0]">
			<FinancialTransaction>
				<TransactionID>
					<xsl:value-of select="TransactionID"/>
				</TransactionID>
				<TransactionTypeText>
					<xsl:value-of select="TransactionTypeText"/>
				</TransactionTypeText>
				<TransactionDate>
					<xsl:value-of select="substring(TransactionDate,1,10)"/>
				</TransactionDate>
				<xsl:for-each select="TransactionFeeDetail[FeeDetailFeeCode='REST']">
					<TransactionFeeDetail>
						<FeeDetailID>
							<xsl:value-of select="FeeDetailID"/>
						</FeeDetailID>
						<FeeDetailFeeCodeText>
							<xsl:attribute name="code">
								<xsl:value-of select="FeeDetailFeeCode"/>
							</xsl:attribute>
							<xsl:value-of select="FeeDetailFeeCodeText"/>
						</FeeDetailFeeCodeText>
						<FeeDetailFeeAmount>
							<xsl:choose>
								<xsl:when test="../TransactionTypeText='Charge'">
									<xsl:value-of select="mscef:formatCurrency(string(ChargeAmount))"/>
								</xsl:when>
								<xsl:when test="../TransactionTypeText='Payment'">
									<xsl:value-of select="mscef:formatCurrency(string(PaymentAmount))"/>
								</xsl:when>
								<xsl:when test="../TransactionTypeText='Credit'">
									<xsl:value-of select="mscef:formatCurrency(string(CreditAmount))"/>
								</xsl:when>
								<xsl:when test="../TransactionTypeText='Disbursement'">
									<xsl:value-of select="mscef:formatCurrency(string(DisbursementAmount))"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:message terminate="yes">Unknown transaction type. <xsl:value-of select="../TransactionTypeText"/>
									</xsl:message>
								</xsl:otherwise>
							</xsl:choose>
						</FeeDetailFeeAmount>
					</TransactionFeeDetail>
				</xsl:for-each>
				<TransactionCommentText>
					<xsl:value-of select="TransactionCommentText"/>
				</TransactionCommentText>
				<TransactionPaymentCreditTypeText>
					<xsl:value-of select="TransactionPaymentCreditTypeText"/>
				</TransactionPaymentCreditTypeText>
			</FinancialTransaction>
		</xsl:for-each>
	</xsl:template>
	<msxsl:script language="JScript" implements-prefix="mscef">
	<![CDATA[
		
		function formatCurrency(asCurrency){
			asCurrency = asCurrency.replace("\$","");
			asCurrency = asCurrency.replace("\,","");
			return parseFloat(asCurrency);
		}
		function formatTwoDecimalCurrency(asCurrency){
		    if(asCurrency.length==0){
			return "";
			}
			asCurrency = asCurrency.replace("\$","");
			asCurrency = asCurrency.replace("\,","");
			return parseFloat(asCurrency).toFixed(2);
		}
	]]></msxsl:script>
</xsl:stylesheet> 

xml document

CODE --> xml

<Integration>
	<Case InternalID="1612988653" ID="5226206" xmlns:user="http://tylertechnologies.com">
	</Case>
	<FinancialDetail>
		<Transaction>
			<TransactionID>1621246445</TransactionID>
			<TransactionTypeText>Charge</TransactionTypeText>
			<TransactionDate>2010-06-30T00:00:00</TransactionDate>
			<TransactionFeeDetail>
				<FeeDetailID>1624242662</FeeDetailID>
				<FeeDetailFeeCode>CRMTRAF5</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Crim/Traffic Surcharge 2005</FeeDetailFeeCodeText>
				<ChargeAmount>72.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242663</FeeDetailID>
				<FeeDetailFeeCode>LAWLIBCR</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Law Library Criminal</FeeDetailFeeCodeText>
				<ChargeAmount>10.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242664</FeeDetailID>
				<FeeDetailFeeCode>MUNICCTY</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Municipal Fines-County Share</FeeDetailFeeCodeText>
				<ChargeAmount>233.3800</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242665</FeeDetailID>
				<FeeDetailFeeCode>10CHAS23</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Chaska (0300) 2/3</FeeDetailFeeCodeText>
				<ChargeAmount>466.6200</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242666</FeeDetailID>
				<FeeDetailFeeCode>CRTCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Court Costs</FeeDetailFeeCodeText>
				<ChargeAmount>3.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242667</FeeDetailID>
				<FeeDetailFeeCode>PROSCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Prosecution Costs</FeeDetailFeeCodeText>
				<ChargeAmount>700.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
		</Transaction>
		<Transaction>
			<TransactionID>1621279946</TransactionID>
			<TransactionTypeText>Charge</TransactionTypeText>
			<TransactionDate>2010-07-06T00:00:00</TransactionDate>
			<TransactionFeeDetail>
				<FeeDetailID>1624281693</FeeDetailID>
				<FeeDetailFeeCode>CRTCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Court Costs</FeeDetailFeeCodeText>
				<ChargeAmount>20.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
		</Transaction>
		<Transaction>
			<TransactionID>1621541452</TransactionID>
			<TransactionTypeText>Payment</TransactionTypeText>
			<TransactionDate>2010-08-06T00:00:00</TransactionDate>
			<TransactionFeeDetail>
				<FeeDetailID>1624242664</FeeDetailID>
				<FeeDetailFeeCode>MUNICCTY</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Municipal Fines-County Share</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>32.2800</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242665</FeeDetailID>
				<FeeDetailFeeCode>10CHAS23</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Chaska (0300) 2/3</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>64.5400</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242666</FeeDetailID>
				<FeeDetailFeeCode>CRTCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Court Costs</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.4100</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624281693</FeeDetailID>
				<FeeDetailFeeCode>CRTCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Court Costs</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>2.7700</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
		</Transaction>
		<Transaction>
			<TransactionID>1621746487</TransactionID>
			<TransactionTypeText>Disbursement</TransactionTypeText>
			<TransactionDate>2010-09-01T00:00:00</TransactionDate>
			<TransactionFeeDetail>
				<FeeDetailID>1624242664</FeeDetailID>
				<FeeDetailFeeCode>MUNICCTY</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Municipal Fines-County Share</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>32.2800</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242665</FeeDetailID>
				<FeeDetailFeeCode>10CHAS23</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Chaska (0300) 2/3</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>64.5400</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624242666</FeeDetailID>
				<FeeDetailFeeCode>CRTCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Court Costs</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.4100</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
			<TransactionFeeDetail>
				<FeeDetailID>1624281693</FeeDetailID>
				<FeeDetailFeeCode>CRTCOSTS</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Court Costs</FeeDetailFeeCodeText>
				<ChargeAmount>0.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>2.7700</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
				<RecipientAccountID>1610014856</RecipientAccountID>
				<NameLast>MN Department of Finance</NameLast>
			</TransactionFeeDetail>
		</Transaction>
		<Transaction>
			<TransactionID>1639560336</TransactionID>
			<TransactionTypeText>Charge</TransactionTypeText>
			<TransactionDate>2016-07-11T00:00:00</TransactionDate>
			<TransactionFeeDetail>
				<FeeDetailID>1650110685</FeeDetailID>
				<FeeDetailFeeCode>REST</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Restitution</FeeDetailFeeCodeText>
				<ChargeAmount>500.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
			</TransactionFeeDetail>
		</Transaction>
		<Transaction>
			<TransactionID>1639560337</TransactionID>
			<TransactionCommentText>Testing</TransactionCommentText>
			<TransactionTypeText>Adjustment</TransactionTypeText>
			<TransactionDate>2016-07-11T00:00:00</TransactionDate>
			<TransactionFeeDetail>
				<FeeDetailID>1650110685</FeeDetailID>
				<FeeDetailFeeCode>REST</FeeDetailFeeCode>
				<FeeDetailFeeCodeText>Restitution</FeeDetailFeeCodeText>
				<ChargeAmount>-500.0000</ChargeAmount>
				<CreditAmount>0.0000</CreditAmount>
				<DisbursementAmount>0.0000</DisbursementAmount>
				<PaymentAmount>0.0000</PaymentAmount>
			</TransactionFeeDetail>
		</Transaction>
	</FinancialDetail>
</Integration> 

RE: How do I add exception to my xslt code

Quote (momo2000)

greater than zero
Do you mean nonzero? Because your one example has a value that is less than zero.

If you go back to thread426-1767600: How do I get out put for required elements? in my first response, you will see a fragment of XSLT that I intended for you to use to replace the once instance of <xsl:otherwise>...</xsl:otherwise> that appears in your XSLT. I will repeat it here, modified as suggested lower in that thread, and with your new message:

CODE --> XSLT_Fragment

<xsl:otherwise>
	<xsl:choose>
	<xsl:when test="count((ChargeAmount | PaymentAmount | CreditAmount | DisbursementAmount)[number() != 0]) = 1">
		<xsl:for-each select="(ChargeAmount | PaymentAmount | CreditAmount | DisbursementAmount)[number() != 0]">
		<xsl:value-of select="."/> 
		</xsl:for-each>
	</xsl:when>
        <xsl:when test="count((ChargeAmount | PaymentAmount | CreditAmount | DisbursementAmount)[number() != 0]) &gt; 1">
		<xsl:message terminate="yes">Transaction has more than one amount type.</xsl:message>
	</xsl:when>
	<xsl:otherwise>
		<xsl:message terminate="yes">Unknown transaction type. <xsl:value-of select="../TransactionTypeText"/>
		</xsl:message>
	</xsl:otherwise>
	</xsl:choose>
</xsl:otherwise> 

momo2000 please plug this in and see if it works for you.

Tom Morrison
Hill Country Software

RE: How do I add exception to my xslt code

(OP)
Yes I meant non-zero amount. Negative amount is acceptable. I did add the code you provided and it is working. Do I still need to have &gt; 1 in my code?

RE: How do I add exception to my xslt code

If you are referring to <xsl:when test-"count(...)[number() != 0] &gt; 1"> in my fragment, that is the test that is determining if more than one of the *Amount nodes contains a non-zero value, so that the message (which describes the situation) contained within that <xsl:when> leg will be emitted.

To expand on the previous thread:
test="count((ChargeAmount | PaymentAmount | CreditAmount | DisbursementAmount)[number() != 0]) = 1"
This tests that exactly one of the four *Amount nodes contains a number that is non-zero.

test="count((ChargeAmount | PaymentAmount | CreditAmount | DisbursementAmount)[number() != 0]) &gt; 1"
This tests for the situation that more than one of the four *Amount nodes contains a number that is non-zero.

<xsl:for-each select="(ChargeAmount | PaymentAmount | CreditAmount | DisbursementAmount)[number() != 0]">
This changes the context to the *Amount node that has a non-zero value (because it is inside an <xsl:when> that has guaranteed there is only one such non-zero node). Besides using <xsl:value-of select="."/> to obtain that non-zero value, you can also use something like <xsl:value-of select="substring-before(local-name(.),'Amount')"/> to retrieve which node contained the non-zero amount (don't know if that's useful or not).

Tom Morrison
Hill Country Software

RE: How do I add exception to my xslt code

(OP)
Thanks for your help. With your help my code is now working as expected.

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