Xsl 1.0 to xsl 3.0 conversion issue

37 Views Asked by At
xsl 1.0 version :

    <xsl:element name="CategoryCodes">
            <xsl:copy-of select="attribute::*" />
            <xsl:for-each select="GuestRoomInfo">
                <xsl:choose>
                    <xsl:when test="@Code=3">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=5">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=6">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=10">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=12">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=13">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=19">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=24">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=26">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=28">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                    <xsl:when test="@Code=47">
                        <xsl:call-template name="HotelInfo_CategoryCodes_GuestRoomInfo" />
                    </xsl:when>
                </xsl:choose>
            </xsl:for-each>
            
Tried to convert into xsl 3.0 as mention below:

    <xsl:template match="CategoryCodes" name="CategoryCodes">
        <xsl:copy-of select="*" />
        <xsl:element name="CategoryCodes">
            <xsl:apply-templates select="GuestRoomInfo" mode="HotelInfo_CategoryCodes_GuestRoomInfo">
                <xsl:with-param name="selectedCodes" select="(3, 5, 6, 10, 12, 13, 19, 24, 26, 28, 47)" />
            </xsl:apply-templates>
        </xsl:element>
    </xsl:template>

Expecting the compatible xsl 3.0 version xslt from xsl 1.0. So tried to do indexing with the available feature of select functionality but didn't work.

Please help in providing the optimistic approach for this in xslt 3.0 version.

1

There are 1 best solutions below

0
Martin Honnen On

Whether XSLT 1 or 2 or 3, you could simplify the for-each with all the nested xsl:choose/xsl:when which all seem to call the same named template into a simple apply-templates with a predicate and some or conditions listing all possible values of @Code (I haven't spelled them all out)

<xsl:apply-templates select="GuestRoomInfo[@Code=3 or @Code=5 or .. or @Code=47]"/>

which for XSLT 2 or 3 you could simplify to

<xsl:apply-templates select="GuestRoomInfo[@Code = (3, 5, 6, 10, 12, 13, 19, 24, 26, 28, 47)]"/>

Then your template named HotelInfo_CategoryCodes_GuestRoomInfo needs a match="GuestRoomInfo" and that seems about it; of course using a mode might make sense or be necessary if you have other places where you process GuestRoomInfo by matching.

For more concrete suggestions I agree with the comment, show us minimal but complete samples of the XML input, the XSLT code and the wanted result.