Construct image name used by generated HTML in style sheet : html « 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 » html 
Construct image name used by generated HTML in style sheet


File: Data.xml

<?xml version="1.0" ?>

<tables>

  <table>
    <table-name>Conference</table-name>
    <number-of-legs>4</number-of-legs>
    <table-top-material type="laminate">Ash</table-top-material>
    <table-shape>Oblong</table-shape>
    <retail-price currency="USD">1485</retail-price>
  </table>
</tables>


File: Transform.xslt
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="/">
    <html>
      <head>
        <title>Three Real Tables</title>
        <style type="text/css">
          .tname
          {font-family:Tahoma;font-size:14pt;font-weight:bold}
          .tdesc {font-family:Tahoma;font-size:10pt.tsaletxt
          {font-family:Tahoma;font-size:14pt;font-weight:bold;color:gray;}
          .tprice
          {font-family:Tahoma;font-size:18pt;font-weight:bold;color:red;text-align:center}
        </style>
      </head>
      <body>
        <xsl:apply-templates select="/tables/table">
          <xsl:sort select="table-name" />
        </xsl:apply-templates>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="table">
    <table border="0" cellpadding="10" bgcolor="lightyellow">
      <tr>
        <td>
          <img src="{table-name}.gif"
            alt="The {table-name} Table" />
        </td>
        <td>
          <div class="tname">
            The '
            <xsl:value-of select="table-name" />
            ' Table
          </div>
          <p />
          <div class="tdesc">
            A useful
            <xsl:value-of select="number-of-legs" />
            -leg
            <xsl:value-of select="table-shape" />
            table with easy
            <br />
            to clean
            <xsl:value-of select="table-top-material" />
            -effect
            <xsl:value-of select="table-top-material/@type" />
            top.
          </div>
          <p />
          <div class="tsaletxt">OUR SALE PRICE ONLY</div>
          <xsl:apply-templates select="retail-price" />
        </td>
      </tr>
    </table>
    <p />
  </xsl:template>

  <xsl:template match="retail-price">
    <div class="tprice">
      <xsl:choose>
        <xsl:when test="@currency = 'USD'">$</xsl:when>
        <xsl:when test="@currency = 'GBP'">?</xsl:when>
        <xsl:when test="@currency = 'EURO'">E</xsl:when>
        <xsl:when test="@currency = 'YEN'">Y</xsl:when>
      </xsl:choose>
      <xsl:value-of select="format-number(., '#,##0.00')" />
    </div>
  </xsl:template>

</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Three Real Tables</title><style type="text/css">
          .tname
          {font-family:Tahoma;font-size:14pt;font-weight:bold}
          .tdesc {font-family:Tahoma;font-size:10pt.tsaletxt
          {font-family:Tahoma;font-size:14pt;font-weight:bold;color:gray;}
          .tprice
          {font-family:Tahoma;font-size:18pt;font-weight:bold;color:red;text-align:center}
        </style></head>
   <body>
      <table border="0" cellpadding="10" bgcolor="lightyellow">
         <tr>
            <td><img src="Conference.gif" alt="The Conference Table"></td>
            <td>
               <div class="tname">
                              The '
                              Conference
                              ' Table
                            
               </div>
               <p></p>
               <div class="tdesc">
                              A useful
                              4
                              -leg
                              Oblong
                              table with easy
                              <br>
                              to clean
                              Ash
                              -effect
                              laminate
                              top.
                            
               </div>
               <p></p>
               <div class="tsaletxt">OUR SALE PRICE ONLY</div>
               <div class="tprice">$1,485.00</div>
            </td>
         </tr>
      </table>
      <p></p>
   </body>
</html>

 
Related examples in the same category
1. Output various html tags
2. Output html img tag
3. One html tag per template
4. Wrap HTML tags in template
5. Format output with HTML tags
6. html output method to make br tags come out as
7. Output html with frameset
8. Transformation of book information into XHTML with sorting
9. Output whole xhtml document
10. Add more format with html tags
11. Format output with font
12. Use blockquote to output value from xml
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.