output a table without loop : template match « 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 » template match 
output a table without loop


File: Data.xml
<?xml version="1.0" ?>

<customer-list>
  <customer>
    <name>
      <first>A</first>
      <last>B</last>
    </name>
    <order>C</order>
    <order>D</order>
  </customer>

</customer-list>

File: Transform.xslt

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

  <xsl:template match="/">
    <HTML>
      <HEAD>
        <TITLE>Customers</TITLE>
      </HEAD>
      <BODY>
        <TABLE BORDER="1" >
          <xsl:apply-templates select="customer-list/customer" />
        </TABLE>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="customer">
    <TR><TH ALIGN="left">
      <xsl:apply-templates select="name"/>
    </TH></TR>
    <xsl:apply-templates select="order"/>
  </xsl:template>

  <xsl:template match="order">
    <TR><TD>
      <xsl:apply-templates/>
    </TD></TR>
  </xsl:template>

  <xsl:template match="name">
    <xsl:value-of select="last" />, 
    <xsl:value-of select="first" />
  </xsl:template>

</xsl:stylesheet>

Output:

<HTML>
   <HEAD>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <TITLE>Customers</TITLE>
   </HEAD>
   <BODY>
      <TABLE BORDER="1">
         <TR>
            <TH ALIGN="left">B, 
                   A
            </TH>
         </TR>
         <TR>
            <TD>C</TD>
         </TR>
         <TR>
            <TD>D</TD>
         </TR>
      </TABLE>
   </BODY>
</HTML>

 
Related examples in the same category
1. Define and use template
2. Locate parent tags and get value from children tags
3. Select value from an element with value-of
4. Get two values in one template
5. match an element
6. output in template
7. set match mode to fulltext
8. match and get value operations with namespace
9. Call a template with parameter
10. template mode="index"
11. template with parameters
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.