﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" />
  <xsl:strip-space elements="*" />
  <xsl:template match="bookdata">
    <root>
      <layout-master-set>
        <simple-page-master master-name="page-layout" page-height="11in" page-width="8in">
          <region-body margin="1in" region-name="body" background-color="#dddddd" />
        </simple-page-master>
      </layout-master-set>
      <page-sequence master-reference="page-layout">
        <flow flow-name="body">
          <table>
            <table-column column-number="1" column-width="25%" />
            <table-column column-number="2" column-width="60%" />
            <table-column column-number="3" column-width="15%" />
            <table-header font-weight="bold">
              <table-row>
                <table-cell border="1pt solid black" padding="4pt">
                  <block>ISBN Number</block>
                </table-cell>
                <table-cell border="1pt solid black" padding="4pt">
                  <block>Title</block>
                </table-cell>
                <table-cell border="1pt solid black" padding="4pt" text-align="right">
                  <block>Price</block>
                </table-cell>
              </table-row>
            </table-header>
            <table-footer font-weight="bold">
              <table-row>
                <table-cell number-columns-spanned="2" border="1pt solid black" padding="4pt">
                  <block>Total Price</block>
                </table-cell>
                <table-cell border="1pt solid black" padding="4pt" text-align="right">
                  <block>
                    <xsl:value-of select="sum(book/price)" />
                  </block>
                </table-cell>
              </table-row>
            </table-footer>
            <table-body>
              <xsl:apply-templates select="book" />
            </table-body>
          </table>
        </flow>
      </page-sequence>
    </root>
  </xsl:template>
  <xsl:template match="book">
    <table-row>
      <table-cell border="1pt solid black" padding="4pt">
        <block>
          <xsl:value-of select="isbn/text()" />
        </block>
      </table-cell>
      <table-cell border="1pt solid black" padding="4pt">
        <block>
          <xsl:value-of select="title/text()" />
        </block>
      </table-cell>
      <table-cell border="1pt solid black" padding="4pt" text-align="right">
        <block>
          <xsl:value-of select="price/text()" />
        </block>
      </table-cell>
    </table-row>
  </xsl:template>
</xsl:stylesheet>
