Subject: Re: [xsl] calling template with name passed in a variable From: Piotr Dobrogost <pd@xxxxxxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 18 Dec 2009 21:53:39 +0100 |
Date: Fri, 18 Dec 2009 02:14:20 GMT From: David Carlisle <davidc@xxxxxxxxx> Subject: Re: [xsl] calling template with name passed in a variable Message-Id: <200912180214.nBI2EKee001410@xxxxxxxxxxxxxxxxxxx>
<xsl:template match="xsd:element[@type=$InPlaceTypesList]"> <xsl:call-template name="@type"/> // <-- error line </xsl:template>
why have a named template there?
To be able to call by template by name with template's name being equal to current value of @type. See description of the goal below.
it would be more natural to do
<xsl:template match="xsd:element"> <xsl:apply-templates select="@type"/> </xsl:template>
<xsl;template match="xsd:element/@type"> the normal code </xsl:template>
<xsl:template match="xsd:element/@type[.=$InPlaceTypesList]" priority="2"> code for these types. </xsl:template>
The above makes the same template matched for any element of $InPlaceTypesList list. The goal is to execute different code (have different template matched) for all xsd:elements with given @type's value from the $InPlaceTypesList list. But I would like to avoid writing by hand a separate match for each element of $InPlaceTypesList list like this;
<xsl:template match="xsd:element[@type='MyTypeX']"> code for THIS type </xsl:template> .... <xsl:template match="xsd:element[@type='MyTypeY']"> code for THIS type </xsl:template>
<xsl:template name="MyNewType1"> code for THIS type </xsl:template>
<xsl:template name="MyNewType2"> code for THIS type </xsl:template>
Incidetally if that's the only use for InPlaceTypesList it is easier and more efficent to have a list of strings rather than elements.
<xsl:param name="InPlaceTypesList" select="('MyTypeX','MyTypeY')"/>
Regards Piotr Dobrogost
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] calling template with nam, Dimitre Novatchev | Thread | Re: [xsl] calling template with nam, G. Ken Holman |
Re: [xsl] Problem in Command Line, Florent Georges | Date | Re: [xsl] calling template with nam, G. Ken Holman |
Month |