I would like to display Party address as non-standard or standard or Foreign address based on the CaseParty/State or Party/State found in the in the xml document. In my xsl I have already checked for the State in the referring xsd document. If the State is not found in the two referring documents, I would like to display the party address as foreign address. My code is not displaying foreign address as foreign which has a different format as I have shown in the desired output.
Desired output
Wrong output
My xml document
Sample referring usps_states.xsd document
Sample referring post-canada.xsd document
My xsl code
Desired output
XML:
<nc:Address>
<nc:AddressFullText>123 Mexico RD Cancun, MM, 12345 Mexico</nc:AddressFullText>
</nc:Address>
Wrong output
XML:
<nc:Address>
<nc:LocationStreet>
<nc:StreetNumberText>123</nc:StreetNumberText>
<nc:StreetPredirectionalText/>
<nc:StreetName>Mexico</nc:StreetName>
<nc:StreetCategoryText>Road</nc:StreetCategoryText>
<nc:StreetPostdirectionalText/>
<nc:StreetExtensionText/>
</nc:LocationStreet>
<nc:LocationCityName>Cancun</nc:LocationCityName>
<nc:LocationStateUSPostalServiceCode>MM</nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>12345</nc:LocationPostalCode>
</nc:Address>
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="67084884" xmlns="">
<Party ID="16770378" InternalPartyID="1614673416">
<NotifyElectronically>0</NotifyElectronically>
<PartyInJailFlag>false</PartyInJailFlag>
<DateOfBirth Current="true">05/31/1960</DateOfBirth>
<Address PartyCorrespondence="true" PartyCurrent="true" ID="17875835" Type="Standard">
<AddressLine2>123 Mexico RD</AddressLine2>
<AddressLine4>Cancun, MM, 12345</AddressLine4>
<Block>123</Block>
<Street>Mexico</Street>
<AddrSfxKy Word="RD">Road</AddrSfxKy>
<City>Cancun</City>
<State>MM</State>
<Zip>12345</Zip>
<Foreign>false</Foreign>
<TimestampCreate>5/28/2015 10:31:50 AM</TimestampCreate>
</Address>
</Party>
</Integration>
Sample referring usps_states.xsd document
XML:
<?xml version="1.0" encoding="US-ASCII"?>
<xs:schema xmlns:structures="[URL unfurl="true"]http://release.niem.gov/niem/structures/3.0/"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:appinfo="[URL unfurl="true"]http://release.niem.gov/niem/appinfo/3.0/"[/URL] xmlns:usps-3.0.1="[URL unfurl="true"]http://publication.niem.gov/niem/codes/usps_states/3.0/1/"[/URL] xmlns:ct="[URL unfurl="true"]http://release.niem.gov/niem/conformanceTargets/3.0/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] targetNamespace="[URL unfurl="true"]http://publication.niem.gov/niem/codes/usps_states/3.0/1/"[/URL] version="1" xsi:schemaLocation="[URL unfurl="true"]http://release.niem.gov/niem/appinfo/3.0/[/URL] ../../../../appinfo/3.0/appinfo.xsd [URL unfurl="true"]http://release.niem.gov/niem/conformanceTargets/3.0/[/URL] ../../../../conformanceTargets/3.0/conformanceTargets.xsd" ct:conformanceTargets="[URL unfurl="true"]http://reference.niem.gov/niem/specification/naming-and-design-rules/3.0/#ReferenceSchemaDocument">[/URL]
<xs:annotation>
<xs:documentation>U.S. Postal Service Supplement</xs:documentation>
</xs:annotation>
<xs:import namespace="[URL unfurl="true"]http://release.niem.gov/niem/structures/3.0/"[/URL] schemaLocation="../../../../structures/3.0/structures.xsd"/>
<xs:simpleType name="USStateCodeSimpleType">
<xs:annotation>
<xs:documentation>A data type for states.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:enumeration value="AK">
<xs:annotation>
<xs:documentation>ALASKA</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="AR">
<xs:annotation>
<xs:documentation>ARKANSAS</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Sample referring post-canada.xsd document
XML:
<?xml version="1.0" encoding="US-ASCII"?>
<xs:schema xmlns:structures="[URL unfurl="true"]http://release.niem.gov/niem/structures/3.0/"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:appinfo="[URL unfurl="true"]http://release.niem.gov/niem/appinfo/3.0/"[/URL] xmlns:can="[URL unfurl="true"]http://release.niem.gov/niem/codes/canada_post/3.0/"[/URL] xmlns:ct="[URL unfurl="true"]http://release.niem.gov/niem/conformanceTargets/3.0/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] targetNamespace="[URL unfurl="true"]http://release.niem.gov/niem/codes/canada_post/3.0/"[/URL] version="1" xsi:schemaLocation="[URL unfurl="true"]http://release.niem.gov/niem/appinfo/3.0/[/URL] ../../../appinfo/3.0/appinfo.xsd [URL unfurl="true"]http://release.niem.gov/niem/conformanceTargets/3.0/[/URL] ../../../conformanceTargets/3.0/conformanceTargets.xsd" ct:conformanceTargets="[URL unfurl="true"]http://reference.niem.gov/niem/specification/naming-and-design-rules/3.0/#ReferenceSchemaDocument">[/URL]
<xs:import namespace="[URL unfurl="true"]http://release.niem.gov/niem/structures/3.0/"[/URL] schemaLocation="../../../structures/3.0/structures.xsd"/>
<xs:simpleType name="CanadianProvinceCodeSimpleType">
<xs:restriction base="xs:token">
<xs:enumeration value="BC">
<xs:annotation>
<xs:documentation>British Columbia</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="MB">
<xs:annotation>
<xs:documentation>Manitoba</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="NB">
<xs:annotation>
<xs:documentation>New Brunswick</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
My xsl code
Code:
<xsl:for-each select="/Integration/Party[@ID=current()/@ID]/Address[@PartyCurrent='true']">
<xsl:call-template name="Address"/>
</xsl:for-each>
<--Address Template-->
<xsl:template name="Address">
<xsl:variable name="vUsState">
<xsl:value-of 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>
<xsl:variable name="vCanadianState">
<xsl:value-of 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"/>
</xsl:variable>
<nc:Address>
<xsl:choose>
<xsl:when test="Block and string-length($vUsState or $vCanadianState)>0">
<!--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:LocationStateUSPostalServiceCode>
<xsl:value-of select="State"/>
</nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>
<xsl:value-of select="Zip"/>
</nc:LocationPostalCode>
</xsl:when>
<xsl:when test="Foreign ='false'">
<!--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:LocationStateUSPostalServiceCode>
<xsl:value-of select="State"/>
</nc:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>
<xsl:value-of select="Zip"/>
</nc:LocationPostalCode>
</xsl:when>
<xsl:otherwise>
<!--Foreign-->
<nc:AddressFullText>
<xsl:value-of select="concat(AddressLine1, '
')"/>
<xsl:value-of select="concat(AddressLine2, '
')"/>
<xsl:value-of select="concat(AddressLine3, '
')"/>
<xsl:value-of select="concat(AddressLine4, '
')"/>
</nc:AddressFullText>
</xsl:otherwise>
</xsl:choose>
</nc:Address>
</xsl:template>