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

  <xsl:output method="text" />

  <!-- store newline in variable in order to avoid ugly -->
  <!-- indentation in templates -->
  <xsl:variable name="newline">
    <xsl:text>&#10;</xsl:text>
  </xsl:variable>

  <xsl:template match="/">

    <xsl:text>1. author names: </xsl:text>
    <xsl:value-of select="$newline" />
    <xsl:for-each select="//author/text()">
      <xsl:value-of select="." />
      <xsl:value-of select="$newline" />
    </xsl:for-each>
    <xsl:value-of select="$newline" />

    <xsl:text>2. average number of authors: </xsl:text>
    <xsl:value-of select="count(//author) div count(//authors)" />
    <xsl:value-of select="$newline" />

    <xsl:text>3. page 2 sentences: </xsl:text>
    <xsl:value-of select="count(//sentence[@page='2'])" />
    <xsl:value-of select="$newline" />

    <xsl:text>4. average publication date: </xsl:text>
    <xsl:value-of select="sum(//date) div count(//date)" />
    <xsl:value-of select="$newline" />

    <xsl:text>5. 3rd sentence length: </xsl:text>
    <xsl:value-of select="string-length((//sentence)[3])" />
    <!-- same as select="string-length(//sentence[2])"; index starts counting at 0 here! -->
    <xsl:value-of select="$newline" />

    <xsl:text>6. 2nd string 1st word: </xsl:text>
    <xsl:value-of select="substring-before((//string)[2], ' ')" />
    <xsl:value-of select="$newline" />

    <xsl:text>7. 1998 - 2000 citations: </xsl:text>
    <xsl:value-of select="$newline" />
    <xsl:for-each select="//citation[(date &gt;= 1998) and (date &lt;= 2000)]/title">
      <xsl:value-of select="." />
      <xsl:value-of select="$newline" />
    </xsl:for-each>
    <xsl:value-of select="$newline" />

    <xsl:text>8. last citation 'newspaper'?: </xsl:text>
    <xsl:value-of select="contains(//citation[last()]/title, 'newspaper')" />

  </xsl:template>

</xsl:stylesheet>



