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 July 22nd, 2016, 09:53 AM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I use variable in select to get @Word?

I would like to use variable vCurrentPoStatus in the select statement below. The following select is not returning anything.
<xsl:value-of select="Type/@Word"/>

I would like to use variable vCurrentPoStatus inside this statement to get the @Word (DISMISSED).
Desired output based on current xml document
Code:
<NotificationEvent notificationType="ProtectionOrderInactivation" internalProtectionOrderID="11271" protectionOrderNumber="1605935" protectionOrderStatusDate="07/21/2016" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">DISMISSED</NotificationEvent>

xslt code
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
		<xsl:if test="Integration/Case/SecurityGroup[not(contains(@Word,'SEAL'))] or not(Integration/Case/SecurityGroup)">
			<xsl:call-template name="ProtectionOrderInactivation"/>
		</xsl:if>
	</xsl:template>
	<!--  -->
	<xsl:template name="ProtectionOrderInactivation">
		<xsl:if test="Integration/ControlPoint='SAVE-PROTECTION-ORDER'">
			<!-- Check for Dismissed -->
			<xsl:if test="Integration/Case/CaseType/@Word='DMA'">
				<xsl:variable name="vControlPointTimestamp" select="mscef:formatDateTimeNumeric(string(/Integration/ControlPoint/@Timestamp))"/>
				<xsl:for-each select="Integration/ProtectionOrder[@Op='E']/Statuses/Status[((@Op='A') or (@Op='E')) and ((Type/@Word='DISMISSED'))]">
					<xsl:variable name="vCurrentPoStatus" select="Statuses/Status[((@Op='A') or (@Op='E'))][mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) &lt;=$vControlPointTimestamp][1]/Type/@Word"/>
					<xsl:if test="$vCurrentPoStatus ='DISMISSED'">
						<NotificationEvent notificationType="ProtectionOrderInactivation">
							<xsl:attribute name="internalProtectionOrderID"><xsl:value-of select="../../@InternalProtectionOrderID"/></xsl:attribute>
							<xsl:attribute name="protectionOrderNumber"><xsl:value-of select="../../ProtectionOrderNumber"/></xsl:attribute>
							<xsl:attribute name="protectionOrderStatusDate"><xsl:value-of select="Date"/></xsl:attribute>
							<xsl:value-of select="Type/@Word"/>
						</NotificationEvent>
					</xsl:if>
				</xsl:for-each>
			</xsl:if>
		</xsl:if>
	</xsl:template>
	<!--  -->
	<msxsl:script language="JScript" implements-prefix="mscef"><![CDATA[
		
		function formatDateTimeNumeric(sDate){
			if(sDate.length==0){
				return "";
			}
			else{
				var oDate=new Date(sDate);
				var str = oDate.getSeconds();
				return "" + oDate.getFullYear().toString() + padZeroes(oDate.getMonth() + 1,2) + padZeroes(oDate.getDate(),2) + padZeroes(oDate.getHours().toString(),2) + padZeroes(oDate.getMinutes(),2) + padZeroes(oDate.getSeconds(),2);  			
			}
		}
		function fixOdysseyTimestamp(sDate){
		/* Replace the ":" between seconds and miliseconds */
			if(sDate.length==0){
				return "";
			}
			else{
				var strParts1 = sDate.split(" ");
				var strTime = strParts1[1];
				var strParts2 = strTime.split(":");
				return strParts1[0] + " " + strParts2[0] + ":" + strParts2[1] + ":" + strParts2[2];
			}
		}
	]]></msxsl:script>
</xsl:stylesheet>
xml doc
Code:
<Integration MessageGUID="79e1bb27-0a4d-47ec-a554-3b59c2518b89" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="IXML Case Notification Test" MessageID="96" xmlns="">
	<ControlPoint Timestamp="7/21/2016 9:49:13 AM" UserID="tessing">SAVE-PROTECTION-ORDER</ControlPoint>
	<Case InternalID="1623057636" ID="14870832" xmlns:user="http://tylertechnologies.com">
		<FiledDate>07/21/2016</FiledDate>
		<CaseCategory>FAM</CaseCategory>
		<CaseType Word="DMA">Domestic Abuse</CaseType>
		<SecurityGroup Word="CONFPOR">Conf - Protective Order</SecurityGroup>
		<ProtectionOrders>
			<ProtectionOrder Op="E" InternalProtectionOrderID="11271">
				<Deleted>false</Deleted>
				<ProtectionOrderNumber>1605935</ProtectionOrderNumber>
				<Issued>07/21/2016</Issued>
				<Expiration>10/29/2016</Expiration>
				<Type Word="OFP">Order for Protection</Type>
				<Statuses>
					<Status Op="A">
						<Current>true</Current>
						<Active>No</Active>
						<Date Op="A">07/21/2016</Date>
						<Type Op="A" Word="DISMISSED">Dismissed</Type>
						<TimestampCreate Op="A">07/21/2016 09:49:13:763</TimestampCreate>
					</Status>
					<Status>
						<Current>false</Current>
						<Active>Yes</Active>
						<Date>07/21/2016</Date>
						<Type Word="SBJOCOR">Corrected - Signed By Judicial Officer</Type>
						<TimestampCreate>07/21/2016 09:48:58:313</TimestampCreate>
					</Status>
				</Statuses>
			</ProtectionOrder>
		</ProtectionOrders>
	</Case>
	<Fees xmlns:user="http://tylertechnologies.com"/>
	<ProtectionOrder Op="E" InternalProtectionOrderID="11271" xmlns:user="http://tylertechnologies.com">
		<Deleted>false</Deleted>
		<ProtectionOrderNumber>1605935</ProtectionOrderNumber>
		<Issued>07/21/2016</Issued>
		<Expiration>10/29/2016</Expiration>
		<Type Word="OFP">Order for Protection</Type>
		<Statuses>
			<Status Op="A">
				<Current>true</Current>
				<Active>No</Active>
				<Date Op="A">07/21/2016</Date>
				<Type Op="A" Word="DISMISSED">Dismissed</Type>
				<TimestampCreate Op="A">07/21/2016 09:49:13:763</TimestampCreate>
			</Status>
			<Status>
				<Current>false</Current>
				<Active>Yes</Active>
				<Date>07/21/2016</Date>
				<Type Word="SBJOCOR">Corrected - Signed By Judicial Officer</Type>
				<TimestampCreate>07/21/2016 09:48:58:313</TimestampCreate>
			</Status>
		</Statuses>
	</ProtectionOrder>
</Integration>
 
Old July 22nd, 2016, 10:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You do

Code:
<xsl:for-each select="Integration/ProtectionOrder[@Op='E']/Statuses/Status[((@Op='A') or (@Op='E')) and ((Type/@Word='DISMISSED'))]">
which iterates over a set of Status elements, and then you do

Code:
                    <xsl:variable name="vCurrentPoStatus" select="Statuses/Status[((@Op='A') or (@Op='E'))][mscef:formatDateTimeNumeric(mscef:fixOdysseyTimestamp(string(TimestampCreate))) &lt;=$vControlPointTimestamp][1]/Type/@Word"/>
which starts by selecting the Statuses child of the context item, but the context item is a Status element which does not have a child called Statuses.
__________________
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 (July 22nd, 2016)





Similar Threads
Thread Thread Starter Forum Replies Last Post
application.word object variable not set jnd03022009 VB Components 1 February 3rd, 2009 01:15 AM
Using variable as fieldname in SELECT statement elygp SQL Server 2000 3 April 26th, 2007 10:14 AM
Using a Variable in Select Into anubhav.kumar SQL Server 2000 2 May 26th, 2005 11:02 AM
Setting a variable using Select Case Adam ASP.NET 1.0 and 1.1 Basics 2 September 4th, 2004 02:09 PM
Using a variable in a SELECT WHERE query scottiegirl MySQL 25 April 15th, 2004 05:28 PM





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