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

Calling a template from within an template

Subject: Calling a template from within an template
From: Tony Fabian <tf@xxxxxxxxxxxxx>
Date: Fri, 5 Nov 1999 13:04:16 +0100
tony fabian
Hi all,

I have a number of tags (H1,H2,B,P ...) where I want to check if they have a
class and 
an id attribute. I have seperate templates for each element. Do I have to
repeat that code 
for every single element or can I store that code in a seperate (named? )
template and then 
include or call that template from within the template. (Does that make
sence?) 

Here is a snip of  my code:
<!-- existing code start --->
<xsl:template match="h1">       
        <xsl:if test =".[@class != '']">
        		<xsl:attribute name="class"><xsl:value-of
select="@class"/></xsl:attribute>
        </xsl:if>

         <xsl:if test =".[@id != '']">
           <a>
          		<xsl:attribute name="name"><xsl:value-of
select="@id"/></xsl:attribute>
           </a>
        </xsl:if> 
	<xsl:apply-templates />	
</xsl:template>
<!-- existing code end --->


Here is what I really want to do:

<xsl:template match="h1">
	<h1>
       		<xsl:call-template name="stdTemplate" />        	
	</h1>
</xsl:template>

<xsl:template match="h2">
	<h2>
       		<xsl:call-template name="stdTemplate" />        	
	</h2>
</xsl:template>


<xsl:template name="stdTemplate">       
        <xsl:if test =".[@class != '']">
        		<xsl:attribute name="class"><xsl:value-of
select="@class"/></xsl:attribute>
        </xsl:if>

         <xsl:if test =".[@id != '']">
           <a>
           		<xsl:attribute name="name"><xsl:value-of
select="@id"/></xsl:attribute>
           </a>
        </xsl:if> 
	<xsl:apply-templates />	
</xsl:template>


Any ideas?

Kind regards

Tony


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.