Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find and display CaseParty address? 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
US
My xml document has 2 addresses.
One under

XML:
/Integration/Case/CaseParty/Address
and another one under
Code:
XML:
/Integration/Party/Address[@PartyCurrent='true']
I only want to display the Address which is under

XML:
/Integration/Party/Address[@PartyCurrent='true']
but if that there is no Address there, then I want to display the Address under

XML:
/Integration/Party/Address[@PartyCurrent='true']
How do I do this?

My xml document


XML:
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="[URL unfurl="true"]http://tsgweb.com"[/URL] xmlns:IXML="[URL unfurl="true"]http://tsgweb.com"[/URL] xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67084533" xmlns="">
<Case Op="E" InternalID="1617088326" ID="12120229" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
    <CaseParty ID="16731290" InternalCasePartyID="1634787102" InternalPartyID="1614631672">
        <Connection Word="DFD" BaseConnection="DF" ID="36370323" InternalCasePartyConnectionID="1636469444">
            <Description>Defendant</Description>
        </Connection>
        <Address CaseCorrespondence="true" ID="17875824" Type="Standard">
            <AddressLine2>3712 Testing RD</AddressLine2>
            <AddressLine4>St Paul, NY, 21457</AddressLine4>
            <Block>3712</Block>
            <Street>Testing</Street>
            <AddrSfxKy Word="RD">Road</AddrSfxKy>
            <City>St Paul</City>
            <State>NY</State>
            <Zip>21457</Zip>
            <Foreign>false</Foreign>
            <TimestampCreate>5/27/2015 10:34:08 AM</TimestampCreate>
        </Address>
        <TimestampCreate>1/29/2015 5:04:53 PM</TimestampCreate>
        <TimestampChange/>
    </CaseParty>
</Case>
<Party ID="16731290" InternalPartyID="1614631672">
    <Address PartyCorrespondence="true" PartyCurrent="true" ID="17867956" Type="Standard">
        <AddressLine2>1906 3RD AVE S #36</AddressLine2>
        <AddressLine4>Denver, CO, 55408</AddressLine4>
        <Block>1906</Block>
        <Street>3RD AVE S #36</Street>
        <City>Denver</City>
        <State>CO</State>
        <Zip>87459</Zip>
        <Foreign>false</Foreign>
    </Address>
</Party>
</Integration>

My xsl is displaying the address under Party. This is not the address I want. I want the address under CaseParty

Code:
<xsl:for-each select="/Integration/Party[@ID=current()/@ID]/Address[@PartyCurrent='true']">
 
It would seem that xsl:choose is the most obvious way to do this. XSLT has xsl:if, but of course there is not xsl:else. Instead xsl:choose presents the n-way decision capability.

If this decision appears only one place in your XSLT, then something as simple as this:

Code:
[indent]<xsl:choose>
<xsl:when test="/Integration/Case/CaseParty/Address">
[indent]<xsl:apply-templates select="/Integration/Case/CaseParty/Address"/>[/indent]
</xsl:when>
<xsl:otherwise>
[indent]<xsl:apply-templates select="/Integration/Party[@ID=current()/@ID]/Address[@PartyCurrent='true']"/>[/indent]
</xsl:otherwise>
</xsl:choose>[/indent]

...

<xsl:template match="Address">
[indent]<!-- process the Address here -->[/indent]
</xsl:template>
[sup]Typed, not tested[/sup]

If you need the Address multiple times, then one possibility is to capture the ID of the desired address, perhaps in a global variable, and then use that ID value later in the stylesheet:
Code:
<xsl:stylesheet ...>
...
<!-- xsl:variable declared as top-level elements are global variables -->
<xsl:variable name="desiredAddressID"><xsl:choose>
[indent][indent]<xsl:when test="/Integration/Case/CaseParty/Address"><xsl:value-of select="/Integration/Case/CaseParty/Address/@ID"/></xsl:when>
<xsl:otherwise><xsl:value-of select="/Integration/Party[@ID=current()/@ID]/Address[@PartyCurrent='true']/@ID"/></xsl:otherwise>
</xsl:choose></xsl:variable>[/indent][/indent]

...  when you want to output the address

[indent]<xsl:apply-templates select="//Address[@ID = $desiredAddressID]"/>[/indent]
...
<xsl:template match="Address">
[indent]<!-- process the Address here -->[/indent]
</xsl:template>
[sup]Typed, not tested[/sup]


Tom Morrison
Hill Country Software
 
Hello Tom, I forgot (seriously) to mention that I am calling a Address template because the address need to be formatted either non-US standard, Standard or Foreign. You code is working however the address is not formatted because I am not calling Address template. i.e
Code:
<xsl:apply-templates select="Address"/>

Here is how the address is now displayed
XML:
<Address>1906 3RD AVE S #36MINNEAPOLIS, MN, 5540819063RD AVE S #36MINNEAPOLISMN55408false1/29/2015 5:04:27 PM</Address>

Here is the Address Template that is called whenever address element is found.
Code:
<!--
	Template Address
-->
	<xsl:template name="Address">
		<xsl:variable name="vUsState" select="document(concat($gEnvPath,'\Schemas\NiemExchanges\DvsDriverLicenseNotification\niem\codes\usps_states\3.0\1\usps_states.xsd'))/xs:schema/xs:simpleType/xs:restriction/xs:enumeration[@value=current()/State]/@value"/>
		<xsl:variable name="vCanadianState" select="document(concat($gEnvPath,'\Schemas\NiemExchanges\DvsDriverLicenseNotification\niem\codes\canada_post\3.0\post-canada.xsd'))/xs:schema/xs:simpleType/xs:restriction/xs:enumeration[@value=current()/State]/@value"/>
		<nc:Address>
			<xsl:choose>
				<xsl:when test="Block and ($vUsState or $vCanadianState)">
					<!--
						
		Standard
-->
					<nc:LocationStreet>
						<nc:StreetNumberText>
							<xsl:value-of select="Block"/>
						</nc:StreetNumberText>
						<nc:StreetPredirectionalText>
							<xsl:value-of select="PreDir"/>
						</nc:StreetPredirectionalText>
						<nc:StreetName>
							<xsl:value-of select="Street"/>
						</nc:StreetName>
						<nc:StreetCategoryText>
							<xsl:value-of select="AddrSfxKy"/>
						</nc:StreetCategoryText>
						<nc:StreetPostdirectionalText>
							<xsl:value-of select="PostDir"/>
						</nc:StreetPostdirectionalText>
						<nc:StreetExtensionText>
							<xsl:value-of select="normalize-space(concat(UnitKy, ' ' , UnitNum))"/>
						</nc:StreetExtensionText>
					</nc:LocationStreet>
					<nc:LocationCityName>
						<xsl:value-of select="City"/>
					</nc:LocationCityName>
					<nc-3.0.1:LocationStateUSPostalServiceCode>
						<xsl:value-of select="State"/>
					</nc-3.0.1:LocationStateUSPostalServiceCode>
					<nc:LocationPostalCode>
						<xsl:value-of select="Zip"/>
					</nc:LocationPostalCode>
				</xsl:when>
				<!--<xsl:when test="Foreign ='false'">-->
				<xsl:when test="Foreign ='false' and ($vUsState or $vCanadianState)">
					<!--
						
		Non-Standard
-->
					<nc:LocationStreet>
						<nc:StreetFullText>
							<xsl:value-of select="AddressLine1"/>
						</nc:StreetFullText>
						<nc:StreetFullText>
							<xsl:value-of select="AddressLine2"/>
						</nc:StreetFullText>
						<nc:StreetFullText>
							<xsl:value-of select="AddressLine3"/>
						</nc:StreetFullText>
					</nc:LocationStreet>
					<nc:LocationCityName>
						<xsl:value-of select="City"/>
					</nc:LocationCityName>
					<nc-3.0.1:LocationStateUSPostalServiceCode>
						<xsl:value-of select="State"/>
					</nc-3.0.1:LocationStateUSPostalServiceCode>
					<nc:LocationPostalCode>
						<xsl:value-of select="Zip"/>
					</nc:LocationPostalCode>
				</xsl:when>
				<xsl:otherwise>
					<!--
						
		Foreign
-->
					<nc:AddressFullText>
						<xsl:value-of select="concat(AddressLine1, '&#xa;')"/>
						<xsl:value-of select="concat(AddressLine2, '&#xa;')"/>
						<xsl:value-of select="concat(AddressLine3, '&#xa;')"/>
						<xsl:value-of select="concat(AddressLine4, '&#xa;')"/>
					</nc:AddressFullText>
				</xsl:otherwise>
			</xsl:choose>
		</nc:Address>
	</xsl:template>
</xsl:stylesheet>
 
Then simply:
Code:
<xsl:template match="Address"><xsl:call-template name="Address"/></xsl:template>

The apply-templates has the effect of changing the context node to the desired Address node (which you have probably been doing with for-each) prior to the call-template.

Tom Morrison
Hill Country Software
 
I am confused Tom. In my xsl code, where do I add the code you provided?
xsl said:
<xsl:template match="Address"><xsl:call-template name="Address"/></xsl:template>
 
Bottom of the stylesheet. It is just another template, among the several you already have...

Tom Morrison
Hill Country Software
 
I added the code but when I removed Address under `CaseParty` the address under `Party` is not displayed.
 
Please show the relevant code from your XSLT.

Tom Morrison
Hill Country Software
 
I added this
Code:
<xsl:template match="Address"><xsl:call-template name="Address"/></xsl:template>
at the bottom of my stylesheet but nothing happened.
Sample stylesheet
Code:
<xsl:stylesheet version="3.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:mscef="courts.state.mn.us/extfun" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:ext="[URL unfurl="true"]http://courts.state.mn.us/DvsDriverLicenseNotificationExtension/1.0"[/URL] xmlns:exc="[URL unfurl="true"]http://courts.state.mn.us/DvsDriverLicenseNotification/1.0"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:fn="[URL unfurl="true"]http://www.w3.org/2005/xpath-functions"[/URL] xmlns:nc="[URL unfurl="true"]http://release.niem.gov/niem/niem-core/3.0/"[/URL] xmlns:usps="[URL unfurl="true"]http://publication.niem.gov/niem/codes/usps_states/3.0/1/"[/URL] xmlns:usps-3.0.1="[URL unfurl="true"]http://publication.niem.gov/niem/codes/usps_states/3.0/1/"[/URL] xmlns:j="[URL unfurl="true"]http://release.niem.gov/niem/domains/jxdm/5.0/"[/URL] xmlns:exsl="urn:schemas-microsoft-com:xslt" xmlns:nc-3.0.1="[URL unfurl="true"]http://publication.niem.gov/niem/niem-core/3.0/1/"[/URL] extension-element-prefixes="exsl" exclude-result-prefixes="mscef msxsl exsl">
<xsl:template match="Address"><xsl:call-template name="Address"/></xsl:template>
</xsl:stylesheet>
 
No, we need to see the place where you have the xsl:choose that is determining the address...

Tom Morrison
Hill Country Software
 
Hello Tom

The code you provided is working. I am not sure what I had done wrong but it is working! As always thanks for your help. I marked your response as the answer that resolved my issue.
 
Here is where the `<xsl:choose>` is located and it is now working.
Code:
<nc:Address>
				<xsl:choose>
					<xsl:when test="/Integration/Case/CaseParty/Address">
						<xsl:apply-templates select="/Integration/Case/CaseParty/Address"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:apply-templates select="/Integration/Party[@ID=current()/@ID]/Address[@PartyCurrent='true']"/>
					</xsl:otherwise>
				</xsl:choose>
				<nc:AddressFullText>
					<xsl:for-each select="/Integration/Case/CaseParty[Connection/@Word='DFD']/Address">
						<xsl:call-template name="Address"/>
					</xsl:for-each>
				</nc:AddressFullText>
</nc:Address>
 
Tom I am reopening this issue. It appears <nc:Address> is also a child of <nc:AddressFullText> This should not be the case.
The <nc:AddressFullText> is a child of <nc:Address>.
How do I remove the <nc:Address> inside the <nc:AddressFullText>?

Here is my output
XML:
<nc:Address>
		<nc:AddressFullText>
			<nc:Address>
				<nc:LocationStreet>
					<nc:StreetNumberText>3712</nc:StreetNumberText>
					<nc:StreetPredirectionalText/>
					<nc:StreetName>Testing</nc:StreetName>
					<nc:StreetCategoryText>Road</nc:StreetCategoryText>
					<nc:StreetPostdirectionalText/>
					<nc:StreetExtensionText/>
				</nc:LocationStreet>
				<nc:LocationCityName>St Paul</nc:LocationCityName>
				<nc-3.0.1:LocationStateUSPostalServiceCode>MN</nc-3.0.1:LocationStateUSPostalServiceCode>
				<nc:LocationPostalCode>55101</nc:LocationPostalCode>
			</nc:Address>
		</nc:AddressFullText>
		<nc:LocationStreet>
			<nc:StreetFullText/>
			<nc:StreetNumberText/>
			<nc:StreetPreDirectionalText/>
			<nc:StreetName/>
			<nc:StreetCategoryText/>
			<nc:StreetPostDirectionalText/>
			<nc:StreetExtensionText/>
		</nc:LocationStreet>
		<nc:AddressRecipientName/>
		<nc:LocationCityName/>
		<nc-3.0.1:LocationStateUSPostalServiceCode/>
		<nc:LocationCanadianProvinceCode/>
		<nc:LocationPostalCode/>
	</nc:Address>
 
The output does not appear to agree with what you have posted previously.

Can you post just the XSL? If possible post the entire XSLT, but at least the all the areas where you are using <xsl:apply-templates select="[tt]XPath for Adress nodeset[/tt]"/>, <xsl:call-template name="Address"/> as well the two templatea <xsl:template name="Address"/> and <xsl:template match="Address"/>.

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top