[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: calling template with name passed in a variable

Subject: Re: calling template with name passed in a variable
From: Piotr Dobrogost <pd@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Dec 2009 21:53:39 +0100
Re:  calling template with name passed in a variable
Date: Fri, 18 Dec 2009 02:14:20 GMT
From: David Carlisle <davidc@xxxxxxxxx>
Subject: Re:  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

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 match="xsd:element/@type">
 the normal code

<xsl:template match="xsd:element/@type[.=$InPlaceTypesList]" priority="2">
  code for these types.

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 match="xsd:element[@type='MyTypeY']">
  code for THIS type

I would like be able to extend xsl easily by adding new types to InPlaceTypesList param and to add new templates handling these new types with templates' names being the same as the names of new types like this;

<xsl:param name="InPlaceTypesList" select="('MyTypeX','MyTypeY','MyNewType1','MyNewType2')"/>

<xsl:template name="MyNewType1">
  code for THIS type

<xsl:template name="MyNewType2">
  code for THIS type

To put this another way; I want to isolate adding templates (with purpose of handling new types) from code needed to invoke (match) them.

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


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.