Hi I must be missing something simple...
I would like dynamically call templates using the value of a node attribute. The XML element has an attribute "type" and I would like to apply a template in different mode depending on the value of "type". If I first get the value of the attribute, I can apply the template in a specific mode: <xsl:choose> <xsl:when test="@type = 'vdtPTD'"> <xsl:apply-templates select="." mode="vdtPTD" /> </xsl:when> ... </xsl:choose> but it requires number of <xsl:when> calls. I thought the following call should work: <xsl:apply-templates select="." mode="@type" /> but it does not. In the result I get the values of all elements. Am I missing something simple or can it not be done? I have tried few options including variables like: <xsl:variable name="one_panel" select="." /> Panel: <xsl:value-of select="$one_panel/@type" /> <xsl:apply-templates select="." mode="$one_panel/@type" /> The type of the panel is printed correctly using <xsl:value-of select="$one_panel/@type" /> but the template in mode="$one_panel/@type" is not applied... The sample XML and stylesheet are below. The calls are in the PANEL template. I am using Xalan that comes with J2EE 1.3.1 Thanks Witold <?xml version="1.0" encoding="UTF-8"?> <VIEWER name="PRPV" version="1.1"> <CAPTION><![CDATA[Property]]></CAPTION> <PANEL name="Key Sample" type="vdtPTD"> <ISKEYPANEL/> <CAPTION><![CDATA[KEY]]></CAPTION> <SIZE>15</SIZE> </PANEL> <PANEL name="NAME_SAMPLE" type="vdtPTS"> <CAPTION><![CDATA[Name]]></CAPTION> <SIZE>100</SIZE> </PANEL> <PANEL name="RS_SAMPLE" type="vdtPTRS"> <CAPTION><![CDATA[RS]]></CAPTION> <SIZE>20</SIZE> </PANEL> <PANEL name="LAND_SAMPLE" type="vdtPTD"> <CAPTION><![CDATA[Land]]></CAPTION> <SIZE>145</SIZE> </PANEL> </VIEWER> and the stylesheet: <?xml version="1.0"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" media-type="text/html" encoding="ISO-8859-1" /> <xsl:template match="VIEWER"> <html> <head> <title><xsl:value-of select="concat(CAPTION, ' Viewer')" /></title> </head> <body> <br /> <xsl:apply-templates select="PANEL" /> <br /> </body> </html> </xsl:template> <xsl:template match="PANEL"> <xsl:choose> <xsl:when test="@type = 'vdtPTD'"> <xsl:apply-templates select="." mode="vdtPTD" /> </xsl:when> <xsl:when test="@type = 'vdtPTRS'"> <xsl:apply-templates select="." mode="vdtPTRS" /> </xsl:when> <xsl:when test="@type = 'vdtPTS'"> <xsl:apply-templates select="." mode="vdtPTS" /> </xsl:when> </xsl:choose> <!-- Does not work. Returns values of all elements <xsl:apply-templates select="." mode="@type" /> --> </xsl:template> <xsl:template match="PANEL" mode="vdtPTD"> PTD. Name: <xsl:value-of select="@name" /> <xsl:if test="ISKEYPANEL"><font color="ff0000"><b> PTD</b></font> </xsl:if> <br /> </xsl:template> <xsl:template match="PANEL" mode="vdtPTRS"> PTRS. Name: <xsl:value-of select="@name" /> <br /> </xsl:template> <xsl:template match="PANEL" mode="vdtPTS"> PTS. Name: <xsl:value-of select="@name" /> <br /> </xsl:template> </xsl:stylesheet>