Subject: RE: [xsl] question on calling templates From: "Hunsberger, Peter" <Peter.Hunsberger@xxxxxxxxxx> Date: Thu, 29 Aug 2002 16:10:23 -0500 |
> I was wondering if there is a way to store template name in the variable and > then call template. No > I want to be able to call diffent body templates depending on the value of a > variable. The answer in this lies in how the variable is created. If the variable is based on the contents of your XML then the solution is to simply to base the XPath used to select the template on the XPATH used to populate the variable. For example, if: <xsl:variable name="gunk" select="root/*/@name"/> causes "gunk" to take on the values of "fee" and "foo" then you do something like:\ <xsl:apply-templates select="/root/*"/> . etc. <xsl:template match="*[@name = 'foo']"> and <xsl:template match="*[@name = 'fee']> The name() or local-name() functions being useful if the match is on element name instead of attribute value. If the variable is getting populated based on some value being passed into the style sheet the problem may be a little harder. If the number of choices is limited and well defined then you use a choose block: <xsl:choose> <xsl:when test="$gunk = 'fee'><xsl:call-template name="fee"/></xsl:when> <xsl:when test="$gunk = 'foo'><xsl:call-template name="foo"/></xsl:when> If you are possibly matching multiple nodes against the template (it doesn't sound like it) then using modal templates is useful instead of using named templates (using named templates is more efficient if there is only one type of match possible.) If the number of choices is large then you may be better off in using a two pass mode where one stylesheet builds a second stylesheet that is then run against the original input. That can be complex or simple, depending on the problem. If none of this helps, you need to tell us ore about the real problem that you are trying to solve. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] question on calling templ, Dion Houston | Thread | [xsl] Parameters set by user, Technik |
RE: [xsl] question on calling templ, Dion Houston | Date | Re: [xsl] question on calling templ, Noel Golding |
Month |