Call template twice : call template « XSLT stylesheet « XML

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML » XSLT stylesheet » call template 
Call template twice


File: Data.xml

<chapter>
  <title>Chapter 1</title>
  <para>para1</para>
  <para author="ar">para2</para>
  <section>
    <title>Chapter 1, Section 1</title>
    <para>para3</para>
    <para>line 1</para>
  </section>
</chapter>

File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template name="titles">
    <xsl:param name="headerElement">h4</xsl:param>
    <xsl:element name="{$headerElement}">
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

  <xsl:template match="chapter/title">
    <xsl:call-template name="titles">
      <xsl:with-param name="headerElement">h1</xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="section/title">
    <xsl:call-template name="titles">
      <xsl:with-param name="headerElement" select="'h2'" />
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="para">
    <p>
      <xsl:apply-templates />
    </p>
  </xsl:template>

  <xsl:template match="chapter">
    <html>
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

Output:

<html>
   <body>
        
      <h1>Chapter 1</h1>
        
      <p>para1</p>
        
      <p>para2</p>
        
          
      <h2>Chapter 1, Section 1</h2>
          
      <p>para3</p>
          
      <p>line 1</p>
        
      
   </body>
</html>

 
Related examples in the same category
1. Call template with parameters
2. template that does the replacement
3. One template calls another template
4. call-template with parameter
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.