Problem in xml transformation using xslt


Joined
Nov 25, 2011
Messages
1
Reaction score
0
Original XML:

<CategoryCodes>
<LocationCategory CodeDescription=""/>
<SegmentCategory CodeDescription=""/>
<HotelCategory CodeDescription="Apartment"/>
<GuestRoomInfo CodeDescription="The total number of rooms in your accommodation" Quantity="20"/>
</CategoryCodes>

1 ) If the atrribute value is CodeDescription change it to Code
2 ) If the value of Code is an empty string then remove the entire element.
Ex: LocationCategory

Required XML:

<CategoryCodes>
<HotelCategory Code="3"/>
<GuestRoomInfo Code="12" Quantity="20"/>
</CategoryCodes>

XSLT :

<xsl:template match="LocationCategory">
<LocationCategory>
<xsl:for-each select="@CodeDescription">
<xsl:variable name="var_code_value" select="."/>
<xsl:variable name="var_code_type" select="'LOC'"/>
<xsl:variable name="var_map_result" select="util:getCode($var_code_type,$var_code_value)"/>
<xsl:attribute name="Code">
<xsl:choose>
<xsl:when test="$var_map_result !=''">
<xsl:value-of select="$var_map_result"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$empty_string"/>
<!--<xsl:value-of select='0'/>-->
</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="@*|node()" />
</LocationCategory>
</xsl:template>
<xsl:template match="LocationCategory[@Code='']"/>

But result is different. So please help:adore:...

Thanx in advance :lol:
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top