Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Outputting Content

Notice that we were able to add text, including HTML tags (such as <p>Blurb:</p>), right into the templates. We can use this capability to transform our XML into HTML by outputting the value of XML elements and attributes within HTML tags:

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        version="1.0">
<xsl:template match="/"><html>
<head>
<title>Primary Outpost</title>
<style type="text/css">
  * { font-family: arial, helvetica, "sans serif" }
  .blurb { border: 1px solid green; 
       font-size: 10pt;
       width: 90%;
       padding: 10px; }
  .admin { text-align: center;
       font-size: 8pt; }
</style>

</head>
<body style="text-align:center">
  <xsl:apply-templates />

</body>
</html>  </xsl:template><xsl:template match="content/blurb">  
<div class="blurb">   <xsl:value-of select="." />
  </div></xsl:template>
<xsl:template match="content/gossip">  
<p>Gossip:</p>  <xsl:value-of select="." /></xsl:template>

<xsl:template match="content/admin">  <div class="admin">   
<xsl:value-of select="." />
  </div></xsl:template>

</xsl:stylesheet>

The HTML that we add can be extensive, such as the page structure and CSS information on the main template, or it can be as simple as the <div></div> elements containing the blurb and admin information.

  • + Share This
  • 🔖 Save To Your Account