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.
Whether XSLT 1 or 2 or 3, you could simplify the
for-eachwith all the nestedxsl:choose/xsl:whenwhich all seem to call the same named template into a simpleapply-templateswith a predicate and someorconditions listing all possible values of@Code(I haven't spelled them all out)which for XSLT 2 or 3 you could simplify to
Then your template named
HotelInfo_CategoryCodes_GuestRoomInfoneeds amatch="GuestRoomInfo"and that seems about it; of course using a mode might make sense or be necessary if you have other places where you processGuestRoomInfoby 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.