<?xml version="1.0" encoding="UTF-8"?>

<!-- 
	
	Stylesheet for Assertion Table
	Version: $Id: assertion-table.xsl,v 1.2 2006/10/14 06:44:22 pdowney Exp $
	
	This stylesheet is copyright (c) 2004 by its authors.  Free
	distribution and modification is permitted, including adding to
	the list of authors and copyright holders, as long as this
	copyright notice is maintained. 
	
	Change Log:
	
	2006-03-22: Arthur Ryman <ryman@ca.ibm.com>
	- corrected stylesheet to include assertions anywhere in document (not just children of spec/body)
	
	2005-10-27: Arthur Ryman <ryman@ca.ibm.com>
	- Implemented assert-summary to create named anchors in the assertion summary table for bidirectional linking with assert.
	
	2005-09-24: Arthur Ryman <ryman@ca.ibm.com>
	- Created.
-->

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:z="http://www.w3.org/2004/zml"
	xmlns:xlink="http://www.w3.org/1999/xlink"
	exclude-result-prefixes="xlink z">

	<!--
		The class parameter defines the value of the class attribute of the assert element to be included in the table.
	-->
	<xsl:param name="class" />

	<xsl:output method="xml" version="1.0" encoding="UTF-8"
		indent="yes" />

	<xsl:template match="/">
		<tbody>
			<tr>
				<th>Id</th>
				<th>Assertion</th>
			</tr>
			<xsl:for-each select=".//assert[@class=$class]">
				<xsl:sort select="@id" />
				<tr>
					<td>
						<assert-summary ref="{@id}" />
					</td>
					<td>
						<!-- Don't use <xsl:copy-of select="*|text()" /> since it copied the namespace attributes. -->
						<xsl:call-template name="copy-elements-and-text" />
					</td>
				</tr>
			</xsl:for-each>
		</tbody>
	</xsl:template>

	<!-- Copies all the element and text node children of the current node. Use this to avoid copy-of which all copies the namespace attributes -->
	<xsl:template name="copy-elements-and-text">
		<xsl:for-each select="*|text()">
			<xsl:apply-templates select="." mode="copy" />
		</xsl:for-each>
	</xsl:template>

	<!-- Copies the current current element node, omitting the namespace attributes of this node and its children, recursively. -->
	<xsl:template match="*" mode="copy">
		<xsl:element name="{name()}">
			<xsl:for-each select="@*">
				<xsl:attribute name="{name()}">
					<xsl:value-of select="." />
				</xsl:attribute>
			</xsl:for-each>
			<xsl:call-template name="copy-elements-and-text" />
		</xsl:element>
	</xsl:template>

	<!-- Copies a text node. -->
	<xsl:template match="text()" mode="copy">
		<xsl:copy-of select="." />
	</xsl:template>


</xsl:stylesheet>

