XML/XSLT stylesheet/html — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:26, 26 мая 2010

Add more format with html tags

File: Data.xml
<?xml version="1.0" standalone="no" ?>
<transcript>
  <student id="STU12345" name="name 1" status="active">
    <home_address>35 Wall Street, Wonderland, NJ</home_address>
    <interests>
      <interest>interest 1</interest>
      <interest>interest 2</interest>
      <interest>interest 3</interest>
    </interests>
  </student>
  <term>
    <heading name="Winter 1999" />
    <course>
      <course-name>course 1</course-name>
      <grade>A-</grade>
      <credits>4</credits>
    </course>
    <course>
      <course-name>course 2</course-name>
      <grade>B+</grade>
      <credits>3</credits>
    </course>
  </term>
  <summary>summary</summary>
  <comments>
     
    comments
  </comments>
</transcript>
File: Transform.xslt
<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="transcript">
    <HTML><BODY>
    <xsl:apply-templates select="student" />
    <HR/>
    <TABLE ALIGN="left" BORDER="1" CELLPADDING="4">
      <TR>
        <TH>Course Name</TH>
        <TH>Grade</TH>
        <TH ALIGN="right">Credits</TH>
      </TR>
      <xsl:for-each select="term/course">
        <xsl:sort select="credits" />        
        <xsl:apply-templates select="." />
      </xsl:for-each>
      
    </TABLE>
    </BODY></HTML>
  </xsl:template>
  <xsl:template match="student">
    <FONT SIZE="6"><B>Student Transcript</B></FONT><P/>
    <FONT SIZE="4"><B>Name: <I>
      <xsl:value-of select="@name" />
      </I><BR/>
      ID: <I>
      <xsl:value-of select="@id" />
    </I></B></FONT><P/>
  </xsl:template>
  <xsl:template match="course">
    <TR>
    <TD><xsl:value-of select="course-name" /></TD>
    <TD><xsl:value-of select="grade" /></TD>
    <TD ALIGN="right"><xsl:value-of select="credits" /></TD>
    </TR>
  </xsl:template>
  
</xsl:stylesheet>
Output:
<HTML>
   <BODY><FONT SIZE="6"><B>Student Transcript</B></FONT><P></P><FONT SIZE="4"><B>Name: <I>name 1</I><BR>
                  ID: <I>STU12345</I></B></FONT><P></P>
      <HR>
      <TABLE ALIGN="left" BORDER="1" CELLPADDING="4">
         <TR>
            <TH>Course Name</TH>
            <TH>Grade</TH>
            <TH ALIGN="right">Credits</TH>
         </TR>
         <TR>
            <TD>course 2</TD>
            <TD>B+</TD>
            <TD ALIGN="right">3</TD>
         </TR>
         <TR>
            <TD>course 1</TD>
            <TD>A-</TD>
            <TD ALIGN="right">4</TD>
         </TR>
      </TABLE>
   </BODY>
</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>



Format output with font

File: Data.xml
<?xml version="1.0" standalone="no" ?>
<transcript>
  <student id="STU12345" name="name 1" status="active">
    <home_address>35 Wall Street, Wonderland, NJ</home_address>
    <interests>
      <interest>interest 1</interest>
      <interest>interest 2</interest>
      <interest>interest 3</interest>
    </interests>
  </student>
  <term>
    <heading name="Winter 1999" />
    <course>
      <course-name>course 1</course-name>
      <grade>A-</grade>
      <credits>4</credits>
    </course>
    <course>
      <course-name>course 2</course-name>
      <grade>B+</grade>
      <credits>3</credits>
    </course>
  </term>
  <term>
    <heading name="Spring 1999" />
    <course>
      <course-name>Physics for Poets</course-name>
      <grade>A</grade>
      <credits>10</credits>
    </course>
    <course>
      <course-name>Poetry for Physicists</course-name>
      <grade>C+</grade>
      <credits>5</credits>
    </course>
  </term>
  <summary>summary</summary>
  <comments>
     
    comments
  </comments>
</transcript>
File: Transform.xslt
<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="transcript">
    <HTML><BODY>
    <xsl:apply-templates select="student" />
    <HR/>
    <TABLE ALIGN="left" BORDER="1" CELLPADDING="4">
      <TR>
        <TH>Course Name</TH>
        <TH>Grade</TH>
        <TH ALIGN="right">Credits</TH>
      </TR>
      <xsl:for-each select="term/course">
        <xsl:sort select="credits" data-type="number" />
        <xsl:apply-templates select="." />
      </xsl:for-each>
      
    </TABLE>
    </BODY></HTML>
  </xsl:template>
  <xsl:template match="student">
    <FONT SIZE="6"><B>Student Transcript</B></FONT><P/>
    <FONT SIZE="4"><B>Name: <I>
      <xsl:value-of select="@name" />
      </I><BR/>
      ID: <I>
      <xsl:value-of select="@id" />
    </I></B></FONT><P/>
  </xsl:template>
  <xsl:template match="course">
    <TR>
    <TD><xsl:value-of select="course-name" /></TD>
    <TD><xsl:value-of select="grade" /></TD>
    <TD ALIGN="right"><xsl:value-of select="credits" /></TD>
    </TR>
  </xsl:template>
  
</xsl:stylesheet>
Output:
<HTML>
   <BODY><FONT SIZE="6"><B>Student Transcript</B></FONT><P></P><FONT SIZE="4"><B>Name: <I>name 1</I><BR>
                  ID: <I>STU12345</I></B></FONT><P></P>
      <HR>
      <TABLE ALIGN="left" BORDER="1" CELLPADDING="4">
         <TR>
            <TH>Course Name</TH>
            <TH>Grade</TH>
            <TH ALIGN="right">Credits</TH>
         </TR>
         <TR>
            <TD>course 2</TD>
            <TD>B+</TD>
            <TD ALIGN="right">3</TD>
         </TR>
         <TR>
            <TD>course 1</TD>
            <TD>A-</TD>
            <TD ALIGN="right">4</TD>
         </TR>
         <TR>
            <TD>Poetry for Physicists</TD>
            <TD>C+</TD>
            <TD ALIGN="right">5</TD>
         </TR>
         <TR>
            <TD>Physics for Poets</TD>
            <TD>A</TD>
            <TD ALIGN="right">10</TD>
         </TR>
      </TABLE>
   </BODY>
</HTML>



Format output with HTML tags

File: Data.xml
<?xml version="1.0"?>
<itinerary>
  <day number="1">day 1</day>
  <day number="2">day 2</day>
  <day number="3">day 3</day>
  <day number="4">day 4</day>
  <day number="5">day 5</day>
  <day number="6">day 6</day>
  <day number="7">day 7</day>
  <day number="8">day 8</day>
  <day number="9">day 9</day>
</itinerary>

File: Transform.xslt
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <head>
        <title>Itinerary</title>
      </head>
      <body>
        <center>
          <xsl:apply-templates select="//day" />
        </center>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="day">
    <h3>
      Day
      <xsl:value-of select="@number" />
    </h3>
    <p>
      <xsl:apply-templates />
    </p>
  </xsl:template>
</xsl:stylesheet>
Output:
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Itinerary</title>
   </head>
   <body>
      <center>
         <h3>
                  Day
                  1
         </h3>
         <p>day 1</p>
         <h3>
                  Day
                  2
         </h3>
         <p>day 2</p>
         <h3>
                  Day
                  3
         </h3>
         <p>day 3</p>
         <h3>
                  Day
                  4
         </h3>
         <p>day 4</p>
         <h3>
                  Day
                  5
         </h3>
         <p>day 5</p>
         <h3>
                  Day
                  6
         </h3>
         <p>day 6</p>
         <h3>
                  Day
                  7
         </h3>
         <p>day 7</p>
         <h3>
                  Day
                  8
         </h3>
         <p>day 8</p>
         <h3>
                  Day
                  9
         </h3>
         <p>day 9</p>
      </center>
   </body>
</html>



html output method to make br tags come out as

File: Data.xml
<wine grape="Cabernet">
  <winery>shop 1</winery>
  <product>product 1</product>
  <year>1996</year>
  <price>11.99</price>
</wine>
File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="html" />
  <xsl:template match="winery">
    <b>
      <font size="10pt">
        <xsl:apply-templates />
        <xsl:text> </xsl:text>
        <xsl:value-of select="../@grape" />
      </font>
    </b>
    <br />
  </xsl:template>
  <xsl:template match="product">
    <i>
      <font size="10pt">
        <xsl:apply-templates />
      </font>
    </i>
    <br />
  </xsl:template>
  <xsl:template match="year | price">
    <font size="10pt">
      <xsl:apply-templates />
    </font>
    <br />
  </xsl:template>
  
</xsl:stylesheet>
Output:

  <b><font size="10pt">shop 1 Cabernet</font></b><br>
  <i><font size="10pt">product 1</font></i><br>
  <font size="10pt">1996</font><br>
  <font size="10pt">11.99</font><br>



One html tag per template

File: Data.xml

File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:template match="emphasis">
    <b>
      <xsl:apply-templates />
    </b>
  </xsl:template>
  <xsl:template match="literal">
    <tt>
      <xsl:apply-templates />
    </tt>
  </xsl:template>
  <xsl:template match="chapter">
    <html>
      <xsl:apply-templates />
    </html>
  </xsl:template>
  <xsl:template match="para">
    <p>
      <xsl:apply-templates />
    </p>
  </xsl:template>
  <xsl:template match="chapter/title">
    <h1>
      <xsl:apply-templates />
    </h1>
  </xsl:template>
</xsl:stylesheet>



Output html img tag

File: Data.xml

<xdata>
</xdata>

File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes" />
  <xsl:template match="xdata">
    <section>
      <xsl:element name="author">
        <xsl:attribute namespace="http://www.w3.org/1999/xlink"
          name="type">simple</xsl:attribute>
        <xsl:attribute namespace="http://www.w3.org/1999/xlink"
          name="href">a.html</xsl:attribute>
      </xsl:element>
      <xsl:apply-templates />
    </section>
  </xsl:template>
</xsl:stylesheet>
Output:

  
<section><author xmlns:ns0="http://www.w3.org/1999/xlink" ns0:type="simple" ns0:href="a.html"/>
</section>



Output html with frameset

File: Data.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<employees>
  <employee eid="1" dept="programming">
    <contact addInfo="info1">
      <name>
        <firstName>Joe</firstName>
        <middleName int="B">Brian</middleName>
        <lastName>Smith</lastName>
      </name>
      <address>
        <street>1 Drive</street>
        <city>Vancouver</city>
        <state>BC</state>
        <zipcode>80210</zipcode>
      </address>
      <phone>
        <tel type="wk">111-1111111</tel>
        <tel type="hm">222-222222</tel>
        <fax>303-4667357</fax>
      </phone>
      <email>a@a.ru</email>
    </contact>
    <hireDate>2008-10-29</hireDate>
  </employee>
  <employee eid="2" dept="training">
    <contact addInfo="info2">
      <name>
        <firstName>Sam</firstName>
        <middleName int="S">Stolte</middleName>
        <lastName>Williams</lastName>
      </name>
      <address>
        <street>1 St.</street>
        <city>Austin</city>
        <state>Texas</state>
        <zipcode>22222</zipcode>
      </address>
      <phone>
        <tel type="wk">512-3467899</tel>
        <tel type="hm">512-4623356</tel>
        <fax>512-3465655</fax>
      </phone>
      <email>s@s.ru</email>
    </contact>
    <hireDate>2000-03-11</hireDate>
  </employee>
</employees>
File: Transform.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <head>
        <title>Frame Document</title>
      </head>
      <frameset cols="30%,*">
        <frame src="nav.html" />
        <xsl:document href="nav.html">
          <html>
            <head>
              <title>Navigation</title>
            </head>
            <body>
              <xsl:apply-templates mode="nav" select="*" />
            </body>
          </html>
        </xsl:document>
        <frame src="body.html" />
        <xsl:document href="body.html">
          <html>
            <head>
              <title>Email Listing</title>
            </head>
            <body>
              <xsl:apply-templates select="*" />
            </body>
          </html>
        </xsl:document>
      </frameset>
    </html>
  </xsl:template>
</xsl:stylesheet>



Output various html tags

File: Data.xml
<poem>
  <title>From Book I</title>
  <excerpt>
    <verse>para1</verse>
    <verse>para2</verse>
    <verse>line 2;</verse>
  </excerpt>
  <excerpt>
    <verse>line 2</verse>
    <verse></verse>
  </excerpt>
</poem>
File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="html" />
  <xsl:template match="poem">
    <html>
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>
  <xsl:template match="title">
    <h1>
      <xsl:apply-templates />
    </h1>
  </xsl:template>
  <xsl:template match="excerpt">
    <p>
      <xsl:apply-templates />
    </p>
    <hr></hr>
  </xsl:template>
  <xsl:template match="verse">
    <xsl:apply-templates />
    <br />
  </xsl:template>

</xsl:stylesheet>
Output:
<html>
   <body>
        
      <h1>From Book I</h1>
        
      <p>
             para1<br>
             para2<br>
             line 2;<br>
           
      </p>
      <hr>
        
      <p>
             line 2<br>
             <br>
           
      </p>
      <hr>
      
   </body>
</html>



Output whole xhtml document

File: Data.xml
<?xml version="1.0"?>
<message>
  You can add processing instructions to a document with the
  <courier>processing-instruction</courier>
  element.
</message>
File: Transform.xslt
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" />
  <xsl:template match="/">
    <html>
      <head>
        <title>HTML Output</title>
      </head>
      <body>
        <p>
          <xsl:apply-templates />
        </p>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
Output:
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>HTML Output</title>
   </head>
   <body>
      <p>
           You can add processing instructions to a document with the
           processing-instruction
           element.
         
      </p>
   </body>
</html>



Transformation of book information into XHTML with sorting

File: Data.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<book isbn="999-99999-9-X">
  <title>XML Primer</title>
  <author>
    <firstName>A</firstName>
    <lastName>B</lastName>
  </author>
  <chapters>
    <frontMatter>
      <preface pages="2" />
      <contents pages="5" />
      <illustrations pages="4" />
    </frontMatter>
    <chapter number="3" pages="44">Advanced XML</chapter>
    <chapter number="2" pages="35">Intermediate XML</chapter>
    <appendix number="B" pages="26">Parsers and Tools</appendix>
    <appendix number="A" pages="7">Entities</appendix>
    <chapter number="1" pages="28">XML Fundamentals</chapter>
  </chapters>
  <media type="CD" />
</book>
File: Transform.xslt
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
  
  <xsl:template match="/book">
    ISBN:<xsl:value-of select="@isbn" />
    Title:<xsl:value-of select="title" />
    by<xsl:value-of select="author/lastName"/>,<xsl:value-of select="author/firstName" />
    <xsl:for-each select="chapters/frontMatter/*">
      <xsl:value-of select="name()" />(<xsl:value-of select="@pages" />pages )
    </xsl:for-each>
    <xsl:for-each select="chapters/chapter">
      <xsl:sort select="@number" data-type="number" order="ascending" />
        Chapter: <xsl:value-of select="@number" />(<xsl:value-of select="@pages" />pages )
    </xsl:for-each>
    <xsl:for-each select="chapters/appendix">
      <xsl:sort select="@number" data-type="text" order="ascending" />
                Appendix<xsl:value-of select="@number" />(<xsl:value-of select="@pages" />pages )
    </xsl:for-each>
        <p style="color: blue">
          Pages:
          <xsl:variable name="pagecount"
            select="sum(chapters//*/@pages)" />
          <xsl:value-of select="$pagecount" />
          <br />
          Media Type:
          <xsl:value-of select="media/@type" />
        </p>
  </xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?>
    ISBN:999-99999-9-X
    Title:XML Primer
    byB,Apreface(2pages )
    contents(5pages )
    illustrations(4pages )
    
        Chapter: 1(28pages )
    
        Chapter: 2(35pages )
    
        Chapter: 3(44pages )
    
                AppendixA(7pages )
    
                AppendixB(26pages )
    <p xmlns="http://www.w3.org/1999/xhtml" style="color: blue">
          Pages:
          151<br/>
          Media Type:
          CD</p>



Use blockquote to output value from xml

File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Transform.xslt"?>
<InvList xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" 
         xsi:noNamespaceSchemaLocation="Schema.xsd">
  <ItemInfo LastUpdated="2005-02-01">
    <ItemName>name 1</ItemName>
    <ItemNum>0001</ItemNum>
    <ItemDesc>description 1</ItemDesc>
    <ItemCost>14.55</ItemCost>
    <ItemLocation>Chicago</ItemLocation>
    <NumInStock>2345</NumInStock>
  </ItemInfo>
  <ItemInfo LastUpdated="2004-12-09">
    <ItemName>name 1</ItemName>
    <ItemNum>0002</ItemNum>
    <ItemDesc>description 2</ItemDesc>
    <ItemCost>9.06</ItemCost>
    <ItemLocation>SanDiego</ItemLocation>
    <NumInStock>13</NumInStock>
  </ItemInfo>
  <ItemInfo LastUpdated="2003-13-19">
    <ItemName>name 1</ItemName>
    <ItemNum>0003</ItemNum>
    <ItemDesc>description 3</ItemDesc>
    <ItemCost>12.34</ItemCost>
    <ItemLocation>Over-seas</ItemLocation>
    <NumInStock>40325</NumInStock>
  </ItemInfo>
</InvList>
File: Transform.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns="http://www.w3.org/TR/REC-html40" xmlns:s="D:\Osborn-McGraw\XML-ComRef\Chapter27">
<xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="no" media-type="text/html" /> 
<xsl:template match="InvList">
  <html>
    <head>
    <title> Inventory List </title>
        <style type="text/css">
        @page {
     margin-left : 15px;
     margin-bottom : 30px;
    margin-right : 15px;
    }
        h1 {
    font-family : Verdana, Arial, sans-serif ;
    font-size : larger;
    background-color : yellow;
    border-bottom-style : double;
    color : Black;
    }
  </style>
  </head>
  <body>
                <xsl:for-each select="ItemInfo">
                <h1>
      <xsl:value-of select="ItemName" /> 
    </h1>
    <blockquote>
      Item Number: <xsl:value-of select="ItemNum" /><br />
      Item Description: <xsl:value-of select="ItemDesc" /><br />
      Item Cost: $<xsl:value-of select="ItemCost" /><br />
      Item Location: <xsl:value-of select="ItemLocation" /><br />  
      Num. In Stock: <xsl:value-of select="NumInStock" />
                </blockquote>
                </xsl:for-each>
  </body>
  </html>
  </xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?><html xmlns:s="D:\Osborn-McGraw\XML-ComRef\Chapter27" xmlns="http://www.w3.org/TR/REC-html40" xmlns:fo="http://www.w3.org/1999/XSL/Format"><head><title> Inventory List </title><style type="text/css">
        @page {
     margin-left : 15px;
     margin-bottom : 30px;
    margin-right : 15px;
    }
        h1 {
    font-family : Verdana, Arial, sans-serif ;
    font-size : larger;
    background-color : yellow;
    border-bottom-style : double;
    color : Black;
    }
  </style></head><body><h1>name 1</h1><blockquote>
      Item Number: 0001<br/>
      Item Description: description 1<br/>
      Item Cost: $14.55<br/>
      Item Location: Chicago<br/>  
      Num. In Stock: 2345</blockquote><h1>name 1</h1><blockquote>
      Item Number: 0002<br/>
      Item Description: description 2<br/>
      Item Cost: $9.06<br/>
      Item Location: SanDiego<br/>  
      Num. In Stock: 13</blockquote><h1>name 1</h1><blockquote>
      Item Number: 0003<br/>
      Item Description: description 3<br/>
      Item Cost: $12.34<br/>
      Item Location: Over-seas<br/>  
      Num. In Stock: 40325</blockquote></body></html>



Wrap HTML tags in template

File: Data.xml

<poem year="1667" type="epic">
  <verse>line 3</verse>
  <verse>line 4</verse>
</poem>
File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
  
  <xsl:template match="verse">
    <html>
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>
  
</xsl:stylesheet>
Output:

  <html><body>line 3</body></html>
  <html><body>line 4</body></html>