Next page Previous page Start of chapter End of chapter

Extracting the value of an element

The xsl:value-of element allows the user to output the string value of an XPath expression evaluated on the input document. This element has a select attribute that contains an XPath expression whose string value is calculated and inserted. The expression can be any XPath expression, since the string value is defined for any XPath value. The context for the XPath expression might be set by the match attribute of the xsl:template element that contains the xsl:value-of element. Here is a full example mixing the the XSLT elements studied so far:

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

   <xsl:template match="/">
      <html>
         <head>
            <title><xsl:value-of select="comment()[1]"/></title>
         </head>
         <body>
            <h1><xsl:value-of select="comment()[1]"/></h1>
            <h2>Conference papers:</h2>
            <ol><xsl:apply-templates select="dblp/inproceedings"/></ol>
            <h2>Journal papers:</h2>
            <ol><xsl:apply-templates select="dblp/article"/></ol>
         </body>
      </html>
   </xsl:template>
   
   <xsl:template match="dblp/inproceedings">
      <li><xsl:apply-templates/></li>
   </xsl:template>
   
   <xsl:template match="dblp/article">
      <li><xsl:apply-templates/></li>
   </xsl:template>

</xsl:stylesheet>

The above XSLT document transforms our XML bibliography into an HTML one. Notice how the string value of a comment node is the content of the comment. The HTML output follows:

<html>
   <head>
      <title>A short bibliography of Massimo Franceschet</title>
   </head>
   <body>
      <h1>A short bibliography of Massimo Franceschet</h1>
      <h2>Conference papers:</h2>
      <ol>
         <li> 
            M. Franceschet
            E. Zimuel
            Modal logic and navigational XPath: an experimental comparison
            Proceedings of the Workshop Methods for Modalities
            156-172
            2005
            http://www.sci.unich.it/~francesc/pubs/m4m05.pdf
            
         </li>
      </ol>
      <h2>Journal papers:</h2>
      <ol>
         <li> 
            M. Franceschet
            B. ten Cate
            Guarded fragments with constants
            Journal of Logic, Language and Information
            14
            3
            281-288
            2005
            http://www.sci.unich.it/~francesc/pubs/jlli05.pdf
            
         </li>
      </ol>
   </body>
</html>
Next page Previous page Start of chapter End of chapter
Caffè XML - Massimo Franceschet