Sample XSLT File for Boolean Operators in Predicates

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Developer's Guide

Sample XSLT File for Boolean Operators in Predicates

XSLT File (predicate.xsl)

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

<xsl:output method="html" />

<!-- Override built-in template rules for elements
and text nodes (note empty <xsl:template element). --> 
<xsl:template match="*" />

<!-- Process the document root. -->
<xsl:template match="/">
    <html>
    <head><title><xsl:value-of select="book/title"/></title></head>
    <h1><xsl:value-of select="book/title"/></h1>
    <body>
        <xsl:apply-templates/>
    </body>
    </html>
</xsl:template>

<xsl:template match="book">
    <xsl:apply-templates select="@*|*"/>
</xsl:template>

<xsl:template match="@copyright[.&gt;=2001]">
    <cite>
        [Copyright <xsl:value-of select="."/>
        (21st century)]
    </cite>
</xsl:template>

<xsl:template match="@copyright[.&lt;=2000]">
    <cite>
        [Copyright <xsl:value-of select="."/>
        (Previous century)]
    </cite>
</xsl:template>

<xsl:template match="book[not(@copyright)]">
    <cite>
        [No copyright date supplied]
    </cite>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="chapter[position()&lt;2]">
    <hr />
    <hr />
    <div style="background-color: teal">
        <h2 align="right">Chapter <xsl:value-of select="position()-2"/>:</h2>
        <xsl:apply-templates select="title"/>
    </div>
    <xsl:apply-templates select="section|notes"/>
</xsl:template>

<xsl:template match="chapter[position()&gt;1]">
    <hr />
    <div style="background-color: teal">
        <h2 align="right">Chapter <xsl:value-of select="position()-2"/>:</h2>
        <xsl:apply-templates select="title"/>
    </div>
    <xsl:apply-templates select="section|notes"/>
</xsl:template>

<xsl:template match="title[name(..)!='book']">
    <xsl:choose>
        <xsl:when test="parent::*[name()='chapter']">
            <h2 align="right"><xsl:value-of select="."/></h2>
        </xsl:when>
        <xsl:otherwise>
            <div style="background-color: silver">
                <h3 align="left"><xsl:value-of select="."/></h3>
            </div>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="section">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="notes">
    <hr width="75%" align="left" />
    <h4>Notes for this chapter:</h4>
    <xsl:apply-templates select="note"/>
</xsl:template>

<xsl:template match="note">
    <p><a name="#{@id}" />[<xsl:value-of select="count(preceding::note[ancestor::chapter//.])+1"/>] <xsl:value-of select="text()"/></p>
</xsl:template>

<xsl:template match="noteref">
  <xsl:variable name="note_num" select="count(preceding::noteref[ancestor::chapter//.])+1"/>
          [<a href="#{@idref}">Note <xsl:value-of select="$note_num"/></a>]
</xsl:template>

<xsl:template match="figure">
    <br clear="left" />
    <img border="1" height="200" width="200" alt="{@caption}" src="{@location}" />
    <br clear="left" />
</xsl:template>

<xsl:template match="text[substring(.,1,1)='T' or substring(.,1,1)='B' or substring(.,1,1)='A' or substring(.,1,1)='P']">
    <p><span style="font-weight: bold; font-size: 18pt; font-family=Verdana,Arial">
        <xsl:value-of select="substring(.,1,1)"/>
        </span>
        <xsl:value-of select="substring(., 2, string-length(.)-1)"/>
        <xsl:apply-templates select="noteref|figure"/>
    </p>
</xsl:template>

<xsl:template match="text[substring(.,1,1)!='T' and substring(.,1,1)!='B' and substring(.,1,1)!='A' and substring(.,1,1)!='P']">
    <p>
        <xsl:apply-templates select="noteref|figure|text()"/>
    </p>
</xsl:template>

</xsl:stylesheet>