I'm trying to use XSLT and replace xml element value by another element if second element value is not empty. In example below I need to replace Item tag value by ItemMaster-CustomChar10 tag value only if it exists
<WmsShippingResultOutSiEs>
<RecordId>6</RecordId>
<ShipmentTransactionId>146</ShipmentTransactionId>
<OutboundOrder>ERIC_1</OutboundOrder>
<WmsShippingResultLineOutSiEs>
<Line>
<RecordId>6</RecordId>
<ShipmentLineSequence>1</ShipmentLineSequence>
<Item>BMS9</Item>
<ItemMaster-CustomChar10>BMS9ALIAS</ItemMaster-CustomChar10>
<WmsShippingResultLineDetailOutSiEs>
<Line>
<ShipmentLineSequence>1</ShipmentLineSequence>
<ShipmentLineDetailTransactionId>143</ShipmentLineDetailTransactionId>
</Line>
</WmsShippingResultLineDetailOutSiEs>
</Line>
<Line>
<RecordId>6</RecordId>
<ShipmentLineSequence>2</ShipmentLineSequence>
<Item>BMS10</Item>
<ItemMaster-CustomChar10/>
<WmsShippingResultLineDetailOutSiEs>
<Line>
<ShipmentLineSequence>1</ShipmentLineSequence>
<ShipmentLineDetailTransactionId>144</ShipmentLineDetailTransactionId>
</Line>
<Line>
<ShipmentLineSequence>2</ShipmentLineSequence>
<ShipmentLineDetailTransactionId>145</ShipmentLineDetailTransactionId>
</Line>
</WmsShippingResultLineDetailOutSiEs>
</Line>
</WmsShippingResultLineOutSiEs>
</WmsShippingResultOutSiEs>
I'm expecting to have a result like
<WmsShippingResultOutSiEs>
<RecordId>6</RecordId>
<ShipmentTransactionId>146</ShipmentTransactionId>
<OutboundOrder>ERIC_1</OutboundOrder>
<WmsShippingResultLineOutSiEs>
<Line>
<RecordId>6</RecordId>
<ShipmentLineSequence>1</ShipmentLineSequence>
<Item>BMS9ALIAS</Item>
<ItemMaster-CustomChar10>BMS9ALIAS</ItemMaster-CustomChar10>
<WmsShippingResultLineDetailOutSiEs>
<Line>
<ShipmentLineSequence>1</ShipmentLineSequence>
<ShipmentLineDetailTransactionId>143</ShipmentLineDetailTransactionId>
</Line>
</WmsShippingResultLineDetailOutSiEs>
</Line>
<Line>
<RecordId>6</RecordId>
<ShipmentLineSequence>2</ShipmentLineSequence>
<Item>BMS10</Item>
<ItemMaster-CustomChar10/>
<WmsShippingResultLineDetailOutSiEs>
<Line>
<ShipmentLineSequence>1</ShipmentLineSequence>
<ShipmentLineDetailTransactionId>144</ShipmentLineDetailTransactionId>
</Line>
<Line>
<ShipmentLineSequence>2</ShipmentLineSequence>
<ShipmentLineDetailTransactionId>145</ShipmentLineDetailTransactionId>
</Line>
</WmsShippingResultLineDetailOutSiEs>
</Line>
</WmsShippingResultLineOutSiEs>
</WmsShippingResultOutSiEs>
All other elements need shouldn't be affected. Is it possible to do it recursivly?
My XSLT code below doesn't work
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
<!-- identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:for-each select="//WmsShippingResultLineDetailOutSiEs/Lines">
<xsl:variable name="host_item" select="ItemMaster-CustomChar10"/>
<xsl:if test="ItemMaster-CustomChar10 !=''">
<Item>
<xsl:value-of select="$host_item"/>
</Item>
</xsl:if>
</xsl:for-each>
Thanks a lot