我想根据
显示正确的<nc:LocationCanadianProvinceCode>
或<nc-3.0.1:LocationStateUSPostalServiceCode>
在xml文档中找到 /Integration/Party/Address/State
,并检查引用的xml文档中是否存在该状态代码。
我的xsl正在运行,但它显示美国和加拿大国家代码。我只想为每个地址显示一个州代码。
所需的输出
<nc:Address>
<nc:LocationStreet>
<nc:StreetFullText>200 Burrard Street</nc:StreetFullText>
<nc:StreetFullText/>
<nc:StreetFullText/>
</nc:LocationStreet>
<nc:LocationCityName>Vancouver</nc:LocationCityName>
<nc:LocationCanadianProvinceCode>BC</nc:LocationCanadianProvinceCode>
<nc:LocationPostalCode>65465</nc:LocationPostalCode>
</nc:Address>
我当前的错误输出
<nc:Address>
<nc:LocationStreet>
<nc:StreetFullText>200 Burrard Street</nc:StreetFullText>
<nc:StreetFullText/>
<nc:StreetFullText/>
</nc:LocationStreet>
<nc:LocationCityName>Vancouver</nc:LocationCityName>
<nc:LocationCanadianProvinceCode>BC</nc:LocationCanadianProvinceCode>
<nc-3.0.1:LocationStateUSPostalServiceCode>BC</nc-3.0.1:LocationStateUSPostalServiceCode>
<nc:LocationPostalCode>65465</nc:LocationPostalCode>
</nc:Address>
我的示例xml文档代码
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67093862" xmlns="">
<Party ID="16769698" InternalPartyID="1614672736">
<Address PartyCorrespondence="true" PartyCurrent="true" ID="17874134" Type="Non Standard">
<AddressLine1>200 Burrard Street</AddressLine1>
<AddressLine4>Vancouver, BC, 65465</AddressLine4>
<City>Vancouver</City>
<State>BC</State>
<Zip>65465</Zip>
<Foreign>false</Foreign>
</Address>
</Party>
</Integration>
我的xsl代码 - 调用地址模板的主题的模板
<!--Template for ext Subject-->
<xsl:template name="Subject">
<ext:Subject>
<xsl:for-each select="/Integration/Case/CaseParty[Connection/@Word='DFD']/Address | /Integration[not(Case/CaseParty[Connection/@Word='DFD']/Address)]/Party[@InternalPartyID=current()/@InternalPartyID]/Address[@PartyCurrent='true']">
<xsl:call-template name="Address"/>
</xsl:for-each>
</ext:Subject>
</xsl:template>
我的xsl代码 - 地址模板
<!--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>
<!--New Canadian Province-->
<nc:LocationCanadianProvinceCode>
<xsl:value-of select="State"/>
</nc:LocationCanadianProvinceCode>
<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)">-->
<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>
<!--New Canadian Province-->
<nc:LocationCanadianProvinceCode>
<xsl:value-of select="State"/>
</nc:LocationCanadianProvinceCode>
<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, '
')"/>
<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>
答案 0 :(得分:0)
查看您的XML,第一个评估为true的xsl:when
是:
<xsl:when test="Foreign ='false' and ($vUsState or $vCanadianState)">
在此范围内你当前输出
<nc:LocationCanadianProvinceCode>
<xsl:value-of select="State"/>
</nc:LocationCanadianProvinceCode>
<nc-3.0.1:LocationStateUSPostalServiceCode>
<xsl:value-of select="State"/>
</nc-3.0.1:LocationStateUSPostalServiceCode>
您可能需要做的是在此处使用嵌套xsl:choose
来再次测试$vUsState
或$vCanadianState
<xsl:choose>
<xsl:when test="$vCanadianState">
<nc:LocationCanadianProvinceCode>
<xsl:value-of select="State"/>
</nc:LocationCanadianProvinceCode>
</xsl:when>
<xsl:otherwise>
<nc-3.0.1:LocationStateUSPostalServiceCode>
<xsl:value-of select="State"/>
</nc-3.0.1:LocationStateUSPostalServiceCode>
</xsl:otherwise>
</xsl:when>
您可能需要在第一个xsl:when
中执行类似的操作。