Hi need to create tags only if values are found in the XML
I am converting XML to XML using XSL
my problem is to create tags only if values are found in the input XML .
I referred many things and created XSL but not working could you please help me .
Thanks!
Input XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href= "D:\Vignesh\Task\RFC\FIS107_24Feb1\MyChanges\XSL SHEET\ThirdIP-HostIP.xsl"?>
<rsm:Waybill xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecificati on:2" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:8"
xmlns:rsm="iata:waybill:1" xmlns:ram="iata:datamodel:3">
<rsm:MessageHeaderDocument>
<ram:ID>01463898855</ram:ID>
<rsm:MessageHeaderDocument>
</rsm:Waybill>
My XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:8"
xmlns:rsm="iata:waybill:1" xmlns:ram="iata:datamodel:3">
<xsl:output method="xml" indent="yes" ></xsl:output>
<xsl:template match="/">
<xsl:if test="rsm:Waybill/rsm:MessageHeaderDocument/ram:ID">
<xsl:text><![CDATA[<ROUTING>]]></xsl:text>
<xsl:text><![CDATA[<ORIGIN>]]></xsl:text>
<xsl:text><![CDATA[ <STATION> ]]></xsl:text>
<xsl:value-of select="/rsm:Waybill/rsm:MasterConsignment/ram:OriginLocation/ram:ID"/>
<xsl:text><![CDATA[</STATION> ]]></xsl:text>
<xsl:text><![CDATA[</ORIGIN>]]></xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
My output will be like
if value is in ram:ID then:
<ROUTING>
<ORIGIN>
<STATION>
01463898855
<STATION>
</ORIGIN>
</ROUTING>
iF NOT THEN : no tags should be created
If you change your the line
<xsl:if test="rsm:Waybill/rsm:MessageHeaderDocument/ram:ID">into
that should also test if there is a value for ram:ID