Create ordered list : list « 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 » list 
Create ordered list


File: Data.xml

<?xml version="1.0"?>
<manual type="assembly" id="model-rocket">
  <parts-list>
    <part label="A" count="1">part 1</part>
    <part label="B" count="1">part 2</part>
    <part label="F" count="4">part 3</part>
    <part label="N" count="3">part 4</part>
    <part label="C" count="1">part 5</part>
  </parts-list>
  <instructions>
    <step>
      Glue
      <part ref="A" />
      and
      <part ref="B" />
      together.
    </step>
    <step>
      For each
      <part ref="F" />
      , .
    </step>
    <step>
      Connect
      <part ref="C" />
    </step>
  </instructions>
</manual>

File: Transform.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="xml" encoding="ISO-8859-1" />
  <xsl:template match="manual">
    <html>
      <head>
        <title>Instructions Guide</title>
      </head>
      <body>
        <h1>Instructions Guide</h1>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>
  <xsl:template match="parts-list">
    <h2>Parts</h2>
    <dl>
      <xsl:apply-templates />
    </dl>
  </xsl:template>
  <xsl:template match="part[@label]">
    <dt>
      <xsl:value-of select="@label" />
    </dt>
    <dd>
      <xsl:apply-templates />
    </dd>
  </xsl:template>
  <xsl:template match="part[@ref]">
    <xsl:variable name="label">
      <xsl:value-of select="@ref" />
    </xsl:variable>
    <xsl:value-of select="//part[@label=$label]"></xsl:value-of>
    <xsl:text> (Part </xsl:text>
    <xsl:value-of select="@ref" />
    <xsl:text>)</xsl:text>
  </xsl:template>
  <xsl:template match="instructions">
    <h2>Steps</h2>
    <ol>
      <xsl:apply-templates />
    </ol>
  </xsl:template>
  <xsl:template match="step">
    <li>
      <xsl:apply-templates />
    </li>
  </xsl:template>

</xsl:stylesheet>


Output:

<?xml version="1.0" encoding="ISO-8859-1"?><html><head><title>Instructions Guide</title></head><body><h1>Instructions Guide</h1>
  <h2>Parts</h2><dl>
    <dt>A</dt><dd>part 1</dd>
    <dt>B</dt><dd>part 2</dd>
    <dt>F</dt><dd>part 3</dd>
    <dt>N</dt><dd>part 4</dd>
    <dt>C</dt><dd>part 5</dd>
  </dl>
  <h2>Steps</h2><ol>
    <li>
      Glue
      part (Part A)
      and
      part (Part B)
      together.
    </li>
    <li>
      For each
      part (Part F)
      , .
    </li>
    <li>
      Connect
      part (Part C)
    </li>
  </ol>
</body></html>

 
Related examples in the same category
1. Create list in transformation
2. Create index number
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.