I would like to Check if VehicleLicensePlateNumber in xml document has a value.
In my xslt this is presented as nc:IdentificationID.
If VehicleLicensePlateNumber has a value, then I want to display it and all child elements of j:ConveyanceRegistrationPlateIdentification in xslt code.
If the VehicleLicensePlateNumber has no value in xml document then I want to skip all elements in j:ConveyanceRegistrationPlateIdentification.
I need to do this because sometimes an xml document may not have a VehicleLicensePlateNumber and for that reason the document fails the schema validation.
How do I do this?
Sample xml document
xslt code
In my xslt this is presented as nc:IdentificationID.
If VehicleLicensePlateNumber has a value, then I want to display it and all child elements of j:ConveyanceRegistrationPlateIdentification in xslt code.
If the VehicleLicensePlateNumber has no value in xml document then I want to skip all elements in j:ConveyanceRegistrationPlateIdentification.
I need to do this because sometimes an xml document may not have a VehicleLicensePlateNumber and for that reason the document fails the schema validation.
How do I do this?
Sample 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="IXML Case Notification Test" MessageID="67077798" xmlns="">
<Case Op="E" InternalID="1617004658" ID="12007544" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
<Charge ID="10781361" PartyID="12290304" InternalChargeID="1616630646" InternalPartyID="704622831" xmlns:reslib="urn:reslib">
<ChargeOffenseDate>06/29/2014</ChargeOffenseDate>
<Vehicle>
<VehicleLicensePlateNumber>912KUZ</VehicleLicensePlateNumber>
</Vehicle>
</Charge>
</Case>
</Integration>
xslt code
Code:
<!--Charge Details Template-->
<xsl:template name="ChargeDetails">
<ext:Vehicle>
<j:ConveyanceRegistrationPlateIdentification>
<xsl:choose>
<xsl:when test="/Vehicle/VehicleLicensePlateNumber">
<nc:IdentificationID>
<xsl:value-of select="/Vehicle/VehicleLicensePlateNumber"/>
</nc:IdentificationID>
</xsl:when>
<xsl:otherwise>
<nc:IdentificationID>
<xsl:value-of select="/Integration/Citation/Vehicle/VehicleLicensePlateNumber"/>
</nc:IdentificationID>
</xsl:otherwise>
</xsl:choose>
<nc:IdentificationJurisdiction>
<!--Check if PlateState is US or Canadian-->
<xsl:variable name="vVehicleLicensePlateState">
<xsl:value-of select="../Vehicle/VehicleLicensePlateState"/>
</xsl:variable>
<xsl:variable name="vUsVehicleLicensePlateStateCode" 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=$vVehicleLicensePlateState]/@value"/>
<xsl:choose>
<xsl:when test="string-length($vUsVehicleLicensePlateStateCode)>0">
<nc-3.0.1:JurisdictionUSPostalServiceCode>
<xsl:value-of select="$vUsVehicleLicensePlateStateCode"/>
</nc-3.0.1:JurisdictionUSPostalServiceCode>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vCanadianVehicleLicensePlateState">
<xsl:value-of select="../Vehicle/VehicleLicensePlateState"/>
</xsl:variable>
<xsl:variable name="vCanadianVehicleLicensePlateStateCode" 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=$vCanadianVehicleLicensePlateState]/@value"/>
<xsl:choose>
<xsl:when test="string-length($vCanadianVehicleLicensePlateStateCode)>0">
<nc:JurisdictionCanadianProvinceCode>
<xsl:value-of select="$vCanadianVehicleLicensePlateStateCode"/>
</nc:JurisdictionCanadianProvinceCode>
</xsl:when>
<xsl:otherwise>
<nc:JurisdictionText>
<xsl:value-of select="/Integration/Citation/Agency/@Word"/>
</nc:JurisdictionText>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</nc:IdentificationJurisdiction>
</j:ConveyanceRegistrationPlateIdentification>
</ext:Vehicle>
</xsl:template>