<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xlink="http://www.w3.org/TR/xlink"
  xmlns:xindr="http://www.isogen.com/papers/xindirection.xml"
  xmlns:xindrf="http://www.isogen.com/functions/xindirection"
  xmlns:saxon="http://icl.com/saxon"
  xmlns:func="http://exslt.org/functions"
  xmlns:fcommon="http://exslt.org/common"
  extension-element-prefixes="func xindrf"
>

<xsl:import href="./xindirect-functions.xsl"/>

<xsl:output 
  method="xml" 
  indent="no"
  omit-xml-declaration="no" 
  encoding="UTF-8"
/>


<xsl:template match="/">
  <html>
    <body>
      <div>
      <hr/>
      <h2>Input Document</h2>
      <pre>
      <xsl:apply-templates mode="echo-markup"/>
      </pre>
      </div>
      <div>
      <hr/>
      <h2>Debug Report</h2>
      <xsl:apply-templates select="//links"/>
      <xsl:apply-templates select="//xindr:indirectorset"/>
      <xsl:apply-templates select="//paras"/>
      </div>
    </body>
  </html>
</xsl:template>

<xsl:template match="links">
  <div>
    <h2>Links</h2>
    <table border="1" width="100%">
      <xsl:apply-templates/>
    </table>
  </div>
</xsl:template>

<xsl:template match="xlink:simple">
  <tr>
    <td><a name="{generate-id()}"
      /><xsl:text>[</xsl:text
      ><xsl:value-of select="generate-id()"
      /><xsl:text>] Initial pointer: </xsl:text>
      <xsl:value-of select="@href"/><xsl:text>: </xsl:text>
      <xsl:apply-templates/>
      <br/><xsl:text>Direct targets: </xsl:text>
      <xsl:apply-templates 
          select="xindrf:resolve-xpointer-url(., 'as-resource')" 
          mode="generate-link-to"/>
    </td>
    <td>
      <xsl:text>Ultimate targets: </xsl:text>
      <xsl:variable name="members" select="xindrf:resolve-xpointer-url(.)"/>
      <xsl:for-each select="$members">
        <br/>
        <a href="#{generate-id()}"
        ><xsl:value-of select="generate-id()"
        /></a>: <code><xsl:apply-templates select="." mode="echo-markup"/></code>
      </xsl:for-each>
    </td>
  </tr>
</xsl:template>

<xsl:template match="paras">
  <div>
    <h2>Paragraphs</h2>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<xsl:template match="para">
  <p
    ><a name="{generate-id()}"
    /><xsl:text>[</xsl:text
    ><xsl:value-of select="generate-id()"
    /><xsl:text
    >]</xsl:text
  ><xsl:apply-templates
  /></p>
</xsl:template>

<xsl:template match="xindr:indirectorset">
  <div>
    <h2>Indirectors</h2>
    <table border="1" width="100%">
      <xsl:apply-templates/>
    </table>
  </div>
</xsl:template>

<xsl:template match="xindr:indirector">
  <xsl:variable name="direct-target" select="xindrf:resolve-xpointer-url(., 'as-resource')"/>
  <tr>
    <td><a name="{generate-id()}"
      /><xsl:text>[</xsl:text
      ><xsl:value-of select="generate-id()"
      /><xsl:text>] Pointer: '</xsl:text
      ><xsl:value-of select="@href"
      /><xsl:text>'. </xsl:text
      ><br/><xsl:text>Comment: </xsl:text
      ><xsl:apply-templates/>
    </td>
    <td>
      <xsl:text>Direct targets: </xsl:text
      >
      <xsl:apply-templates select="$direct-target" mode="generate-link-to"/>
    </td>
  </tr>  
</xsl:template>

<xsl:template match="*" mode="generate-link-to">
    <br/>
    <a href="#{generate-id()}"
    ><xsl:value-of select="generate-id()"
    /></a>: <code><xsl:apply-templates select="." mode="echo-markup"/></code>
</xsl:template>

<xsl:template name="echo-element-markup">
  <xsl:text>&lt;</xsl:text><xsl:value-of select="name()"/>
  <xsl:for-each select="./attribute::*">
    <xsl:text>  </xsl:text><xsl:value-of select="name()"/>=<xsl:value-of select="."/>
  </xsl:for-each>
  <xsl:text>&gt;</xsl:text>
  <xsl:apply-templates mode="echo-markup"/>
  <xsl:text>&lt;</xsl:text><xsl:value-of select="name()"/><xsl:text>&gt;</xsl:text>  
</xsl:template>

<xsl:template match="*" mode="echo-markup">
  <xsl:call-template name="echo-element-markup"/>
</xsl:template>

</xsl:stylesheet> <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
<metaInformation>
<scenarios ><scenario default="yes" name="test1" userelativepaths="yes" externalpreview="no" url="testdoc&#x2D;01.xml" htmlbaseurl="" processortype="internal" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->