1]" : axis « XSLT stylesheet « XML " /> 1]" : axis « XSLT stylesheet « XML "/>

for-each select="listitem[position() > 1]" : axis « 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 » axis 
for-each select="listitem[position() > 1]"


File: Data.xml

<?xml version="1.0"?>
<list xml:lang="en">
  <title>title 1</title>
  <listitem>item 1</listitem>
  <listitem>item 2</listitem>
  <listitem>item 3</listitem>
  <listitem xml:lang="sw">item 4</listitem>
  <listitem xml:lang="en-gb">item 5</listitem>
  <listitem xml:lang="zu">item 6</listitem>
  <listitem xml:lang="jz">item 7</listitem>
</list>

File: Transform.xslt

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

  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <head>
        <title><xsl:value-of select="list/title"/></title>
      </head>
      <body style="font-family: sans-serif;">
        <xsl:apply-templates select="list"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="list">
    <table border="1" cellpadding="5" cellspacing="5">
      <tr>
        <td style="background: black; color: white; 
                   font-weight: bold; font-size: 125%;" 
                   width="100" align="right">
          <xsl:if test="count(listitem) > 1">
            <xsl:attribute name="rowspan">
              <xsl:value-of select="count(listitem)"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:value-of select="title"/>
        </td>
        <td>
          <xsl:value-of select="listitem[1]"/>
        </td>
      </tr>
      <xsl:for-each select="listitem[position() &gt; 1]">
        <tr>
          <td>
            <xsl:value-of select="."/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>

</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>title 1</title>
   </head>
   <body style="font-family: sans-serif;">
      <table border="1" cellpadding="5" cellspacing="5">
         <tr>
            <td style="background: black; color: white;                     font-weight: bold; font-size: 125%;" width="100" align="right" rowspan="7">title 1</td>
            <td>item 1</td>
         </tr>
         <tr>
            <td>item 2</td>
         </tr>
         <tr>
            <td>item 3</td>
         </tr>
         <tr>
            <td>item 4</td>
         </tr>
         <tr>
            <td>item 5</td>
         </tr>
         <tr>
            <td>item 6</td>
         </tr>
         <tr>
            <td>item 7</td>
         </tr>
      </table>
   </body>
</html>

 
Related examples in the same category
1. List All customers: /report/customer
2. template match="//customer"
3. template match="//customer[1]/name"
4. template match="//processing-instruction()"
5. Match all from root
6. for-each and select="."
7. tag with index
8. select="." (dot)
9. Match an element
10. match element with certain attribute value
11. match="text()|@*"
12. match="@*|node()"
13. select down to a certain level and its attribute
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.