Problem in xml transformation using xslt

Discussion in 'XML' started by bosesuparna, Nov 25, 2011.

  1. bosesuparna

    bosesuparna

    Joined:
    Nov 25, 2011
    Messages:
    1
    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:
    bosesuparna, Nov 25, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wolfgang
    Replies:
    2
    Views:
    825
    Wolfgang
    Apr 9, 2004
  2. Wolfgang
    Replies:
    0
    Views:
    414
    Wolfgang
    Apr 6, 2004
  3. Kevin Brown
    Replies:
    3
    Views:
    546
    Kevin Brown
    Aug 28, 2004
  4. SG
    Replies:
    2
    Views:
    841
    Mike Schilling
    Aug 15, 2007
  5. Binaryx
    Replies:
    3
    Views:
    5,090
    Peter Flynn
    Apr 14, 2012
Loading...

Share This Page