<?xml version="1.0" encoding="utf-8"?>
<!-- 

    Copyright (C) 2006 W3C (R) (MIT ERCIM Keio), All Rights Reserved.
    W3C liability, trademark and document use rules apply.

    http://www.w3.org/Consortium/Legal/ipr-notice
    http://www.w3.org/Consortium/Legal/copyright-documents

    $Header: /w3ccvs/WWW/2002/ws/databinding/edcopy/patterns/explode_patterns.xsl,v 1.11 2007/04/19 11:17:25 pdowney Exp $

-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:pat="http://www.w3.org/2002/ws/databinding/patterns/6/09/"
    xmlns:ex="http://www.w3.org/2002/ws/databinding/patterns/6/09/"
    exclude-result-prefixes="">

    <xsl:import href="../common/xml-to-string.xsl"/>
 
    <xsl:output method="html" name="overview" indent="yes" encoding="UTF-8"/>
    
    <xsl:param name="dir"/>
    <xsl:variable name="ns" select="'ex:'"/>
    <xsl:variable name="sep" select="'/'"/>
    <xsl:variable name="w3c.root">../../../../../../..</xsl:variable>
    <xsl:param name="examplesPath">../../../../examples/6/09/</xsl:param>
    <xsl:param name="examplesDir">../../examples/6/09/</xsl:param>
    <xsl:variable name="detectedPatterns" select="document(concat($examplesDir,$sep,'examples-patterns.xml'))/detected-patterns"/>
    
    <xsl:template match="/">
        <!--<xsl:apply-templates select="pat:patterns/pat:pattern[@xml:id = 'StringElement']"/>-->
        <xsl:apply-templates select="pat:patterns/pat:pattern"/>
    </xsl:template>
    
    <xsl:template match="ex:pattern">
        <xsl:param name="patternId" select="@xml:id"/>
        <xsl:variable name="patternElementId" select="@element"/> 
        <xsl:variable name="operation" select="concat('echo',$patternId)"/>
        <xsl:variable name="element" select="$operation"/>
        
        <xsl:variable name="patternDir" select="concat($dir,$sep,$patternId,$sep)"/>
        <xsl:variable name="overviewFilename" select="'Overview.html'"/>
	<xsl:variable name="examples" select="$detectedPatterns/example/detected/pattern[@name=$patternId]/../../@xml:id"/>

        <xsl:result-document href="{$dir}{$sep}{$patternId}{$sep}{$overviewFilename}" format="overview">

<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
  <head>
    <title><xsl:value-of select="$patternId"/> Pattern</title>
    <link type="text/css" rel="stylesheet" href="../../../../../../../StyleSheets/TR/base.css"/>
<style type="text/css">
div.patternInner pre { margin-left: 1em;
                       margin-top: 0em; margin-bottom: 0em}
div.patternInner { background-color: #d5dee3;
                   border-top-width: 4px;
                   border-top-style: double;
                   border-top-color: #d3d3d3;
                   border-bottom-width: 4px;
                   border-bottom-style: double;
                   border-bottom-color: #d3d3d3;
                   padding: 4px; margin: 0em }

table { empty-cells: show; }

th { color: #000000; background-color: #CCCC99; }

table caption {
	font-weight: normal;
	font-style: italic;
	text-align: left;
	margin-bottom: .5em;
}
</style>
  </head>

  <body xmlns:rddl="http://www.rddl.org/">

            <xsl:comment>

                Copyright (C) 2006 W3C (R) (MIT ERCIM Keio), All Rights Reserved.
                W3C liability, trademark and document use rules apply.
            
                http://www.w3.org/Consortium/Legal/ipr-notice
                http://www.w3.org/Consortium/Legal/copyright-documents
            
		Generated from: <xsl:value-of select="//ex:version"/><xsl:text>
</xsl:text>
            </xsl:comment>

    <div class="head">
      <p>

	<a href="http://www.w3.org/">
	  <img width="72" height="48" alt="W3C" src="{$w3c.root}/Icons/w3c_home"/>
	</a>
      </p>

      <h1><xsl:value-of select="$patternId"/> Pattern </h1>
    </div>

	<div class="patternInner">
	    <pre><xsl:attribute name="xml:space">preserve</xsl:attribute><xsl:apply-templates select="pat:xpath/text()" mode="pre"/></pre>
	</div>

	<p>This is 
		<xsl:choose>
		    <xsl:when test="@status = 'basic'">
			a <a href="{$w3c.root}/2002/ws/databinding/edcopy/basic/basic.html#pattern-{$patternId}">Basic XML Schema Patterns for Databinding 1.0</a>
		    </xsl:when>
		    <xsl:when test="@status = 'advanced'" xml:space='preserve'>
			an <a href="${w3c.root}/2002/ws/databinding/edcopy/advanced/advanced.html#pattern-{$patternId}">Advanced XML Schema Patterns for Databinding 1.0</a>
		    </xsl:when>
		    <xsl:otherwise>
			"<xsl:value-of select="@status"/>"
		    </xsl:otherwise>
		</xsl:choose>
		pattern<xsl:choose>
		    <xsl:when test="count($examples) eq 0">.</xsl:when>
		    <xsl:otherwise>, exhibited by the following <a href="../../../../examples/6/09/">examples</a>:
		    </xsl:otherwise>
		</xsl:choose>
		</p>

		<xsl:if test="count($examples) gt 0">
		<ul>
		<xsl:for-each select="$detectedPatterns/example/detected/pattern[@name=$patternId]/../../@xml:id">
		    <xsl:variable name="exampleId" select="."/>
		    <li>
			<a href="{$examplesPath}{$exampleId}"><xsl:value-of select="$exampleId"/></a>
		    </li>
		</xsl:for-each>
		</ul>
		</xsl:if>

		<xsl:if test="$detectedPatterns/example[@xml:id=$patternId] and
		    not($detectedPatterns/example[@xml:id=$patternId]/detected/pattern[@name=$patternId])">
		<table border='1'>
		<tr><td>
		   <xsl:attribute name="bgcolor">#FF8888</xsl:attribute>
		   ERROR: the <a href="{$patternId}"><xsl:value-of select="concat($patternDir, $patternId)"/></a> example does not contain this pattern.
		</td>
		</tr>
		</table>
		</xsl:if>
    <hr/>
	<xsl:copy-of select="document('address.xml')/suffix/*"/>
	<p>Generated from <a href="patterns.xml">patterns.xml</a> &#x24;Date$</p>
  </body>
</html>
        </xsl:result-document>        
    </xsl:template>

    <xsl:template match="*" mode="pre">
        <xsl:text>&#10;</xsl:text>
        <xsl:call-template name="xml-to-string">
            <xsl:with-param name="include-ns-decls" select="false()"/>
        </xsl:call-template>
        <xsl:text>&#10;</xsl:text>
    </xsl:template>

</xsl:stylesheet>
