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

<xsl:output method="text"/>

<!--
Use <xsl:key/> to select unique elements. See
http://www.bernzilla.com/item.php?id=333 for details.
-->
<xsl:key name="host_id_key" match="host" use="@host_id"/>
<xsl:key name="au_id_key" match="au" use="@au_id"/>

<xsl:template match="/">
<!-- foreach unique HOST -->
<xsl:for-each select="/compare/host_node/host[generate-id() = generate-id(key('host_id_key', @host_id))]">
	<xsl:variable name="this_host_id" select="@host_id"/>
----BEGIN HOST: <xsl:value-of select="$this_host_id"/>----
This message should be sent to <xsl:value-of select="/compare/host_node/host[@host_id = $this_host_id and observed_col = 'platform_status.admin_email']/observed_val"/>, in reference to the cache named <xsl:value-of select="/compare/host_node/host[@host_id = $this_host_id and observed_col = 'caches.name']/observed_val"/>.
	<!-- foreach HOST record that has problems -->
	<xsl:for-each select='/compare/host_node/host[@host_id = $this_host_id and diff != "OK"]'>
		<!--
		<xsl:choose>
		<xsl:when test="observed_col = 'caches_per_au'">
		<xsl:otherwise>
		-->
----BEGIN UNHANDLED DIFF----
Unrecognized mismatch on this host: schema path is <xsl:value-of select="expected_path"/>; Cache Manager column is <xsl:value-of select="observed_col"/>.
----END UNHANDLED DIFF----
		<!--
		</xsl:otherwise>
		</xsl:choose>
		-->
	</xsl:for-each>
	<!-- foreach unique AU -->
	<xsl:for-each select="/compare/archival_unit/au[generate-id() = generate-id(key('au_id_key', @au_id))]">
		<xsl:variable name="this_au_id" select="@au_id"/>
		<!-- foreach AU record for this AU that has problems -->
		<xsl:for-each select='/compare/archival_unit/au[@au_id = $this_au_id and diff != "OK"]'>
			<xsl:choose>
			<xsl:when test="observed_col = 'caches_per_au'">
				<!-- if this host has not archived this AU, ask to archive -->
				<xsl:if test="not(/compare/host-archival_unit/host_au[@host_id = $this_host_id and @au_id = $this_au_id])">
----BEGIN AU ADD REQUEST----
Mismatch: AU requires <xsl:value-of select="expected_val"/> copies, but Cache Manager is reporting
<xsl:value-of select="observed_val"/> extant. We need to add <xsl:value-of select="expected_val - observed_val"/> more.

It appears that your host is not currently archiving this AU. Please
consider adding it to your archive.

AU ID: <xsl:value-of select="$this_au_id"/>
----END AU ADD REQUEST----
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:for-each>
----END HOST----
</xsl:for-each>
</xsl:template>


<!-- keep xsltproc from spewing all unhandled text back at me -->
<xsl:template match="text() | @*"/>

</xsl:stylesheet>
