<?xml version='1.0' encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="no" indent="yes" />

    <xsl:param name="newPath" />
    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:template match="/">
      <xsl:apply-templates />
    </xsl:template>

    <!-- default treatment of text nodes is to ignore -->
    <xsl:template match="text()"/>

    <!-- sometimes we want the contents of text nodes -->
    <xsl:template match="text()" mode='string-to-text'>
      <xsl:value-of select='.' />
    </xsl:template>

    <!-- transform a list of String elements to a comma delimited list -->
    <xsl:template match='List' mode='list-to-comma-delim'>
      <xsl:for-each select="String">
        <xsl:apply-templates select='.' mode='string-to-text' />
        <xsl:if test="position() != last()">
          <xsl:text>, </xsl:text>
        </xsl:if>
      </xsl:for-each>
    </xsl:template>

    <!-- ===== meta data as comment templates ===== -->
    <xsl:template match="comment()" mode='description-as-comment'>
      <xsl:variable name='text' select='.' />
      <xsl:if test='starts-with($text, " @description ")'>
        <literallayout><xsl:value-of select='substring-after($text, " @description ")' /></literallayout>
      </xsl:if>
    </xsl:template>
    <xsl:template match="comment()" mode='productReference-as-comment'>
      <xsl:variable name='text' select='.' />
      <xsl:if test='starts-with($text, " @prodRef ")'>
        <para><emphasis>Product Reference</emphasis>: <xsl:value-of select='substring-after($text, " @prodRef ")' /></para>
      </xsl:if>
    </xsl:template>




    <!-- SYSTEM CONFIGS -->
    <xsl:template match='Configuration[@name="User Extended Attributes"]'>
      <sect3><title>User Extended Attributes</title>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
        <sect4><title>Extended Attributes</title>
          <itemizedlist>
            <xsl:for-each select='Extension/List/String'>
              <listitem><para><xsl:apply-templates select='.' mode='string-to-text' /></para></listitem>
            </xsl:for-each>
          </itemizedlist>
        </sect4>
      </sect3>
    </xsl:template>
    <xsl:template match='Configuration/Extension/UserUIConfig'>
      <sect3><title>User Interface Configuration</title>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <sect4><title>SummaryAttrNames</title>
          <para>Summary attributes for these types are not stored by name, they are stored by id. The id is then translated into a name when the list is created.</para>
          <itemizedlist>
            <xsl:for-each select='SummaryAttrNames/List/String'>
              <listitem><para><xsl:apply-templates select='.' mode='string-to-text' /></para></listitem>
            </xsl:for-each>
          </itemizedlist>
        </sect4>

        <sect4><title>QueryableAttrNames</title>
          <para>User object attributes that can be searched on.</para>
          <itemizedlist>
            <xsl:for-each select='QueryableAttrNames/List/String'>
              <listitem><para><xsl:apply-templates select='.' mode='string-to-text' /></para></listitem>
            </xsl:for-each>
          </itemizedlist>
        </sect4>

        <sect4><title>FindSearchAttrs</title>
          <para>These attributes show up in the popup menus on the find Account, Change Password, and Reset Password pages.</para>
          <itemizedlist>
            <xsl:for-each select='FindSearchAttrs/List/String'>
              <listitem><para><xsl:apply-templates select='.' mode='string-to-text' /></para></listitem>
            </xsl:for-each>
          </itemizedlist>
        </sect4>

        <sect4><title>RepoIndexAttrs</title>
          <para>The attributes are copied to the waveset.object table and indexed so searches against them are very fast.</para>
          <itemizedlist>
            <xsl:for-each select='RepoIndexAttrs/List/String'>
              <listitem><para><xsl:apply-templates select='.' mode='string-to-text' /></para></listitem>
            </xsl:for-each>
          </itemizedlist>
        </sect4>

      </sect3>
    </xsl:template>
    <xsl:template match='Configuration[@authType="ReconPolicy"]'>
      <sect3><title>Reconciliation Policies</title>

        <para><emphasis>Fetch timeout (ms)</emphasis>: <xsl:choose><xsl:when test='Extension/Object/Attribute[@name="fetchTimeout"]'><xsl:value-of select='Extension/Object/Attribute[@name="fetchTimeout"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
        <para><emphasis>List timeout (ms)</emphasis>: <xsl:choose><xsl:when test='Extension/Object/Attribute[@name="listTimeout"]'><xsl:value-of select='Extension/Object/Attribute[@name="listTimeout"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
        <para><emphasis>Maximum Concurrent Resources</emphasis>: <xsl:choose><xsl:when test='Extension/Object/Attribute[@name="maxConcurrentResources"]'><xsl:value-of select='Extension/Object/Attribute[@name="maxConcurrentResources"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
        <para><emphasis>Maximum Queue Size</emphasis>: <xsl:choose><xsl:when test='Extension/Object/Attribute[@name="maxQueueSize"]'><xsl:value-of select='Extension/Object/Attribute[@name="maxQueueSize"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
        <para><emphasis>Native Delete Threshold</emphasis>: <xsl:choose><xsl:when test='Extension/Object/Attribute[@name="nativeDeleteThreshold"]'><xsl:value-of select='Extension/Object/Attribute[@name="nativeDeleteThreshold"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
        <para><emphasis>Post Reconciliation Workflow</emphasis>: <xsl:choose><xsl:when test='Extension/Object/Attribute[@name="postReconWorkflow"]'><xsl:value-of select='Extension/Object/Attribute[@name="postReconWorkflow"]/ObjectRef/@name' /></xsl:when><xsl:otherwise>none</xsl:otherwise></xsl:choose> </para>

        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <xsl:for-each select='Extension/Object/Attribute[@name and child::Object]'>
          <xsl:variable name='resourceType'><xsl:value-of select='@name' /></xsl:variable>
            <xsl:for-each select='Object/Attribute[@name]'>
              <sect4><title>Reconciliation Policies for Resource <xsl:value-of select='@name' /></title>
                <para><emphasis>Resource Type</emphasis>:  <xsl:value-of select='$resourceType' /></para>
                <para><emphasis>Correlation Rule</emphasis>: <xsl:choose><xsl:when test='Object/Attribute[@name="correlationRule"]'><xsl:value-of select='Object/Attribute[@name="correlationRule"]/ObjectRef/@name' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
                <para><emphasis>Confirmation Rule</emphasis>: <xsl:choose><xsl:when test='Object/Attribute[@name="confirmationRule"]'><xsl:value-of select='Object/Attribute[@name="confirmationRule"]/ObjectRef/@name' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>
                <para><emphasis>Proxy Administrator</emphasis>: <xsl:choose><xsl:when test='Object/Attribute[@name="proxyAdmin"]'><xsl:value-of select='Object/Attribute[@name="proxyAdmin"]/ObjectRef/@name' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose> </para>

                <para><emphasis>Configured Situations</emphasis>:</para>
                <informaltable frame='all'>
                  <tgroup cols='2' align='left' colsep='0' rowsep='0'>
                    <colspec colname='situation'/>
                    <colspec colname='action'/>
                    <tbody>
                      <xsl:if test='Object/Attribute[@name="responseUnassignedAccount"]'>
                        <row>
                          <entry>Unassigned Account</entry>
                          <entry><xsl:value-of select='Object/Attribute[@name="responseUnassignedAccount"]/@value' /></entry>
                        </row>
                      </xsl:if>
                      <xsl:if test='Object/Attribute[@name="responseUnmatchedAccount"]'>
                        <row>
                          <entry>Unmatched Account</entry>
                          <entry><xsl:value-of select='Object/Attribute[@name="responseUnmatchedAccount"]/@value' /></entry>
                        </row>
                      </xsl:if>
                      <xsl:if test='Object/Attribute[@name="responseDeletedAccount"]'>
                        <row>
                          <entry>Deleted Account</entry>
                          <entry><xsl:value-of select='Object/Attribute[@name="responseDeletedAccount"]/@value' /></entry>
                        </row>
                      </xsl:if>
                      <xsl:if test='Object/Attribute[@name="responseFoundAccount"]'>
                        <row>
                          <entry>Found Account</entry>
                          <entry><xsl:value-of select='Object/Attribute[@name="responseFoundAccount"]/@value' /></entry>
                        </row>
                      </xsl:if>
                      <xsl:if test='Object/Attribute[@name="responseMissingAccount"]'>
                        <row>
                          <entry>Missing Account</entry>
                          <entry><xsl:value-of select='Object/Attribute[@name="responseMissingAccount"]/@value' /></entry>
                        </row>
                      </xsl:if>
                    </tbody>
                  </tgroup>
                </informaltable>

              </sect4>
            </xsl:for-each>
        </xsl:for-each>

      </sect3>
    </xsl:template>

    <!-- LoginApp -->
    <xsl:template match='LoginApp'>
      <sect3><title>Login Application: <xsl:value-of select='@name' /></title>
        <!-- apply the descripton as comment template -->
        <xsl:apply-templates select='preceding-sibling::comment()' mode='description-as-comment' />

        <para><emphasis>Disabled?</emphasis> <xsl:choose><xsl:when test='@disabled = "true"'> Yes </xsl:when><xsl:otherwise> No </xsl:otherwise></xsl:choose></para>
        <para><emphasis>Obfuscate Login Errors?</emphasis> <xsl:choose><xsl:when test='@obfuscateLoginErrors = "true"'> Yes </xsl:when><xsl:otherwise> No </xsl:otherwise></xsl:choose></para>
        <para><emphasis>Subject Timeout (ms)</emphasis>: <xsl:choose><xsl:when test='@subjectTimeout'><xsl:value-of select='@subjectTimeout' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose></para>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <xsl:variable name='unique-modgroup-list' select='LoginModGroups/ObjectRef[not(@name=following::ObjectRef/@name)]' />
        <xsl:if test='$unique-modgroup-list' >
          <sect4><title>Login Modules</title>
            <itemizedlist>
              <xsl:for-each select="$unique-modgroup-list">
                <listitem><para><xsl:value-of select="./@name" /></para></listitem>
              </xsl:for-each>
            </itemizedlist>
          </sect4>
        </xsl:if>
      </sect3>
    </xsl:template>

    <!-- Login Module -->
    <xsl:template match='LoginModGroup'>
      <sect3><title>Login Module: <xsl:value-of select='@name' /></title>
        <!-- apply the descripton as comment template -->
        <xsl:apply-templates select='preceding-sibling::comment()' mode='description-as-comment' />

        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <sect4><title>Login Entries</title>
          <xsl:apply-templates />
        </sect4>

      </sect3>
    </xsl:template>

    <!-- Login Module -->
    <xsl:template match='LoginConfigEntryRefs/LoginConfigEntryRef'>
      <sect5><title><xsl:value-of select="@authnResourceName" /></title>
        <para><emphasis>Resource Type</emphasis>:  <xsl:value-of select='@authnResourceType' /></para>
        <para><emphasis>Module Type</emphasis>:  <xsl:value-of select='@name' /></para>
        <para><emphasis>Control Type</emphasis>:  <xsl:value-of select='@control' /></para>

        <para><emphasis>Correlation Rule</emphasis>: <xsl:choose><xsl:when test='LoginCorrelationRule/ObjectRef/@name'><xsl:value-of select='LoginCorrelationRule/ObjectRef/@name' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose></para>

        <xsl:variable name='unique-authprop-list' select='AuthnPropertyRefs/AuthnPropertyRef[not(@name=following::AuthnPropertyRef/@name)]' />
        <xsl:if test='$unique-authprop-list' >
          <para><emphasis>Authentication Parameters</emphasis>:</para>
          <itemizedlist>
            <xsl:for-each select="$unique-authprop-list">
              <listitem><para><xsl:value-of select="./@name" /></para></listitem>
            </xsl:for-each>
          </itemizedlist>
        </xsl:if>
      </sect5>
    </xsl:template>


    <!-- organizations -->
    <xsl:template match='Waveset/ObjectGroup'>
      <sect3><title>Organization: <xsl:value-of select='@displayName' /></title>
        <!-- apply the descripton as comment template -->
        <xsl:apply-templates select='preceding-sibling::comment()[position()=1]' mode='description-as-comment' />
        <para><emphasis>System ID</emphasis>:  <systemitem><xsl:value-of select='@id' /></systemitem></para>

        <xsl:if test='PathFromTop/List'>
          <para><emphasis>Path From Top</emphasis>: <systemitem>
              <xsl:for-each select="PathFromTop/List/String">
                <xsl:apply-templates select='.' mode='string-to-text' />
                <xsl:if test="position() != last()">
                  <xsl:text>|</xsl:text>
                </xsl:if>
              </xsl:for-each>
          </systemitem></para>
        </xsl:if>

        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <xsl:variable name='unique-policy-list' select='Policies/ObjectRef[not(@name=following::ObjectRef/@name)]' />
        <xsl:if test='$unique-policy-list' >
          <sect4><title>Policies</title>
            <itemizedlist>
              <xsl:for-each select="$unique-policy-list">
                <listitem><para><xsl:value-of select="./@name" /></para></listitem>
              </xsl:for-each>
            </itemizedlist>
          </sect4>
        </xsl:if>
      </sect3>

    </xsl:template>


    <!-- Account Policy -->
    <xsl:template match='Policy[@class="com.waveset.policy.LighthouseAccountPolicy"]' >
      <sect3><title>Account Policy: <xsl:value-of select='@name' /></title>
        <xsl:if test='Description'>
          <literallayout><xsl:value-of select='Description' /></literallayout>
        </xsl:if>

        <para><emphasis>Account ID Policy</emphasis>: <xsl:choose><xsl:when test='GeoAttributes/Object/Attribute[@name="accountIdPolicy"]'><xsl:value-of select='GeoAttributes/Object/Attribute[@name="accountIdPolicy"]/ObjectRef/@name' /></xsl:when><xsl:otherwise>None</xsl:otherwise></xsl:choose></para>
        <para><emphasis>Source of new account ID</emphasis>: <xsl:choose><xsl:when test='GeoAttributes/Object/Attribute[@name="idSource"]/@value'><xsl:value-of select='GeoAttributes/Object/Attribute[@name="idSource"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose></para>

        <para><emphasis>Password Policy</emphasis>: <xsl:choose><xsl:when test='GeoAttributes/Object/Attribute[@name="passwordPolicy"]'><xsl:value-of select='GeoAttributes/Object/Attribute[@name="passwordPolicy"]/ObjectRef/@name' /></xsl:when><xsl:otherwise>None</xsl:otherwise></xsl:choose></para>
        <para><emphasis>Source of new account password</emphasis>: <xsl:choose><xsl:when test='GeoAttributes/Object/Attribute[@name="passwordSource"]/@value'><xsl:value-of select='GeoAttributes/Object/Attribute[@name="passwordSource"]/@value' /></xsl:when><xsl:otherwise>not specified</xsl:otherwise></xsl:choose></para>


        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <!-- TODO: include remaining account attributes + interface specific attributes -->

      </sect3>
    </xsl:template>

    <!-- Password Policy -->
    <xsl:template match='Policy[@class="com.waveset.policy.StringQualityPolicy"]' >
      <xsl:variable name="stringPolicyType">
        <xsl:choose>
          <xsl:when test='GeoAttributes/Object/Attribute[@name="String Type"]'>
            <xsl:value-of select='GeoAttributes/Object/Attribute[@name="String Type"]/@value' />
          </xsl:when>
          <xsl:otherwise>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="ancestor::tgroup/colspec[@colname=$colnameend]/@colnum"/>
      </xsl:variable>
      <sect3><title><xsl:value-of select='$stringPolicyType' /> Policy: <xsl:value-of select='@name' /></title>
        <xsl:if test='Description'>
          <literallayout><xsl:value-of select='Description' /></literallayout>
        </xsl:if>

        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <sect4><title>String Quality Policies</title>
          <informaltable frame='all'>
            <tgroup cols='2' align='left' colsep='1' rowsep='1'>
              <colspec colname='attribute'/>
              <colspec colname='value'/>
              <thead>
                <row>
                  <entry>Policy</entry>
                  <entry>Value</entry>
                </row>
              </thead>
              <tbody>
                <xsl:apply-templates select='GeoAttributes/Object/Attribute' mode='string-policy' />
              </tbody>
            </tgroup>
          </informaltable>
        </sect4>

      </sect3>
    </xsl:template>
    <xsl:template match='Attribute[child::Integer]' mode='string-policy'>
      <row>
        <entry><xsl:value-of select='@name' /></entry>
        <entry><xsl:value-of select='Integer' /></entry>
      </row>
    </xsl:template>
    <xsl:template match='Attribute[child::List]' mode='string-policy'>
      <row>
        <entry><xsl:value-of select='@name' /></entry>
        <entry><xsl:apply-templates select='List' mode='list-to-comma-delim' /></entry>
      </row>
    </xsl:template>

    <!-- RESOURCE -->
    <xsl:template match='Resource' >
      <sect3><title>Resource: <xsl:value-of select='@name' /></title>

        <!-- apply the descripton as comment template -->
        <xsl:apply-templates select='preceding-sibling::comment()' mode='description-as-comment' />

        <para><emphasis>Type</emphasis>:  <xsl:value-of select='@typeString' /></para>

        <!-- special attributes for flat file resources -->
        <xsl:if test='@typeString = "FlatFileActiveSync"'>
          <para><emphasis>Flat File Configuration</emphasis></para>
          <informaltable frame='all'>
            <tgroup cols='2' align='left' colsep='0' rowsep='0'>
              <colspec colname='attribute'/>
              <colspec colname='value'/>
              <tbody>
                <xsl:call-template name='generateFlatFilePropertyRows'>
                  <xsl:with-param name='attribute'>fileFormat</xsl:with-param>
                  <xsl:with-param name='attribute-name'>file format</xsl:with-param>
                </xsl:call-template>
                <xsl:call-template name='generateFlatFilePropertyRows'>
                  <xsl:with-param name='attribute'>fieldDelimiter</xsl:with-param>
                  <xsl:with-param name='attribute-name'>field delimiter</xsl:with-param>
                </xsl:call-template>
                <xsl:call-template name='generateFlatFilePropertyRows'>
                  <xsl:with-param name='attribute'>textQualifier</xsl:with-param>
                  <xsl:with-param name='attribute-name'>text qualifier</xsl:with-param>
                </xsl:call-template>
                <xsl:call-template name='generateFlatFilePropertyRows'>
                  <xsl:with-param name='attribute'>customParser</xsl:with-param>
                  <xsl:with-param name='attribute-name'>custom parser</xsl:with-param>
                  <xsl:with-param name='empty-value-text'>None</xsl:with-param>
                </xsl:call-template>
                <xsl:call-template name='generateFlatFilePropertyRows'>
                  <xsl:with-param name='attribute'>fileEncoding</xsl:with-param>
                  <xsl:with-param name='attribute-name'>file encoding</xsl:with-param>
                </xsl:call-template>
              </tbody>
            </tgroup>
          </informaltable>
        </xsl:if>

        <!-- apply the product reference template -->
        <xsl:apply-templates select='preceding-sibling::comment()' mode='productReference-as-comment' />

        <!-- special handling of resources without a product reference (probably a custom resource) -->
        <xsl:variable name='unique-comment-list' select='preceding-sibling::comment()[starts-with(.," @prodRef ")]' />
        <xsl:if test='not($unique-comment-list)'>
          <para><emphasis>Implementation Class</emphasis>:  <xsl:value-of select='@class' /></para>
        </xsl:if>

        <para><emphasis>Active Sync Enabled?</emphasis>
          <xsl:choose>
            <xsl:when test='contains(@facets,"activesync")'> Yes  (startup type is <xsl:value-of select='@startupType' />)</xsl:when>
            <xsl:otherwise> No </xsl:otherwise>
          </xsl:choose>
        </para>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
        <xsl:if test='child::ResourceAttributes//child::ResourceAttribute[@name = "Proxy Administrator"]/@value | child::ResourceAttributes//child::ResourceAttribute[@name = "correlationRule"]/@value | child::ResourceAttributes//child::ResourceAttribute[@name = "confirmationRule"]/@value'>
          <sect4><title>Referenced Objects</title>
            <itemizedlist>
              <xsl:if test='string-length(child::ResourceAttributes//child::ResourceAttribute[@name = "Proxy Administrator"]/@value) &gt; 0'>
                <listitem><para><emphasis>Proxy User</emphasis>: <xsl:value-of select='child::ResourceAttributes//child::ResourceAttribute[@name = "Proxy Administrator"]/@value' /></para></listitem>
              </xsl:if>
              <xsl:if test='string-length(child::ResourceAttributes//child::ResourceAttribute[@name = "correlationRule"]/@value) &gt; 0'>
                <listitem><para><emphasis>Correlation Rule</emphasis>: <xsl:value-of select='child::ResourceAttributes//child::ResourceAttribute[@name = "correlationRule"]/@value' /></para></listitem>
              </xsl:if>
              <xsl:if test='string-length(child::ResourceAttributes//child::ResourceAttribute[@name = "confirmationRule"]/@value) &gt; 0'>
                <listitem><para><emphasis>Confirmation Rule</emphasis>: <xsl:value-of select='child::ResourceAttributes//child::ResourceAttribute[@name = "confirmationRule"]/@value' /></para></listitem>
              </xsl:if>
            </itemizedlist>
          </sect4>
        </xsl:if>
      </sect3>
    </xsl:template>
    <!-- generate rows of flat file property table -->
    <xsl:template name='generateFlatFilePropertyRows'>
      <xsl:param name="attribute" />
      <xsl:param name="attribute-name" />
      <xsl:param name="empty-value-text">Not specified</xsl:param>
      <row>
        <entry><xsl:value-of select='$attribute-name' /></entry>
        <entry>
          <xsl:choose>
            <xsl:when test='string-length(child::ResourceAttributes/child::ResourceAttribute[@name = $attribute]/@value) &gt; 0'><xsl:value-of select='child::ResourceAttributes/child::ResourceAttribute[@name = $attribute]/@value' /></xsl:when>
            <xsl:otherwise> <xsl:value-of select='$empty-value-text' /> </xsl:otherwise>
          </xsl:choose>
        </entry>
      </row>
    </xsl:template>


    <!-- RULE -->
    <xsl:template match='Rule'>
      <sect3><title>Rule: <xsl:value-of select='@name' /></title>
        <xsl:if test='Comments'>
          <para><xsl:value-of select='Comments' /></para>
        </xsl:if>
        <xsl:if test='@subtype'>
          <para>
            <emphasis>Type</emphasis>: 
            <xsl:choose>
              <xsl:when test='@subtype = "SUBTYPE_ACCOUNT_CORRELATION_RULE"'>Correlation Rule</xsl:when>
              <xsl:when test='@subtype = "SUBTYPE_ACCOUNT_CONFIRMATION_RULE"'>Confirmation Rule</xsl:when>
              <xsl:otherwise><xsl:value-of select='@subtype' /></xsl:otherwise>
            </xsl:choose>
          </para>
        </xsl:if>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
      </sect3>
    </xsl:template>
    <!-- RULE LIBRARY -->
    <xsl:template match='Configuration/Extension/Library'>
      <sect3><title>Rule Library: <xsl:value-of select='/Configuration/@name' /></title>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
        <sect4><title>Documented Rules</title>
          <xsl:apply-templates select='Rule' mode='embedded' />
        </sect4>
      </sect3>
    </xsl:template>
    <xsl:template match='Rule' mode='embedded'>
      <xsl:if test='Comments'>
        <para>
          <emphasis><xsl:value-of select='@name' /></emphasis>
          <xsl:if test='Comments'>: <xsl:value-of select='Comments' /></xsl:if>
        </para>
      </xsl:if>
    </xsl:template>


    <!-- EMAIL TEMPLATE -->
    <xsl:template match='EmailTemplate' >
      <sect3><title>Email Template: <xsl:value-of select='@name' /></title>
        <xsl:if test='Comments'>
          <para><xsl:value-of select='Comments' /></para>
        </xsl:if>
        <para><emphasis>HTML Enabled?</emphasis>  
          <xsl:choose>
            <xsl:when test='@htmlEnabled = "true"'> Yes </xsl:when>
            <xsl:otherwise> No </xsl:otherwise>
          </xsl:choose>
        </para>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
      </sect3>
    </xsl:template>

    <!-- TASK Definition -->
    <xsl:template match='TaskDefinition' >
      <sect3><title>Task Instance: <xsl:value-of select='@name' /></title>
        <xsl:if test='Extension/WFProcess/Comments'>
          <literallayout><xsl:value-of select='Extension/WFProcess/Comments' /></literallayout>
        </xsl:if>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
        <para><emphasis>Runnable from Admin Interface?</emphasis>  
          <xsl:choose>
            <xsl:when test='@visibility = "invisible"'> No </xsl:when>
            <xsl:otherwise> Yes </xsl:otherwise>
          </xsl:choose>
        </para>

        <!-- generate a list of unique sub-processes -->
        <xsl:variable name='unique-process-list' select='Extension/WFProcess/Activity/Action[string-length(@process) &gt; 0][not(@process=following::Action/@process)]' />
        <xsl:if test='$unique-process-list' >
          <sect4><title>Referenced Sub-Processes</title>
            <itemizedlist>
              <xsl:for-each select="$unique-process-list">
                <listitem><para><xsl:value-of select="./@process" /></para></listitem>
              </xsl:for-each>
            </itemizedlist>
          </sect4>
        </xsl:if>

        <!-- generate a list of referenced user forms -->
        <xsl:variable name='unique-form-list' select='Extension/WFProcess/Activity/ManualAction/FormRef/ObjectRef[@type="UserForm"][string-length(@name) &gt; 0][not(@name=following::ObjectRef/@name)]' />
        <xsl:if test='$unique-form-list' >
          <sect4><title>Referenced User Forms</title>
            <itemizedlist>
              <xsl:for-each select="$unique-form-list">
                <listitem><para><xsl:value-of select="./@name" /></para></listitem>
              </xsl:for-each>
            </itemizedlist>
          </sect4>
        </xsl:if>

      </sect3>
    </xsl:template>

    <!-- SUB PROCESS -->
    <xsl:template match='Configuration/Extension/WFProcess' >
      <sect3><title>Sub-Process: <xsl:value-of select='@name' /></title>
        <xsl:if test='Comments'>
          <literallayout><xsl:value-of select='Comments' /></literallayout>
        </xsl:if>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <!-- generate a list of unique sub-processes -->
        <xsl:variable name='unique-process-list' select='Activity/Action[string-length(@process) &gt; 0][not(@process=following::Action/@process)]' />
        <!-- list each sub-process -->
        <xsl:if test='$unique-process-list' >
          <sect4><title>Referenced Sub-Processes</title>
            <itemizedlist>
              <xsl:for-each select="$unique-process-list">
                <listitem><para><xsl:value-of select="./@process" /></para></listitem>
              </xsl:for-each>
            </itemizedlist>
          </sect4>
        </xsl:if>

        <!-- generate a list of referenced user forms -->
        <xsl:variable name='unique-form-list' select='Activity/ManualAction/FormRef/ObjectRef[@type="UserForm"][string-length(@name) &gt; 0][not(@name=following::ObjectRef/@name)]' />
        <xsl:if test='$unique-form-list' >
          <sect4><title>Referenced User Forms</title>
            <itemizedlist>
              <xsl:for-each select="$unique-form-list">
                <listitem><para><xsl:value-of select="./@name" /></para></listitem>
              </xsl:for-each>
            </itemizedlist>
          </sect4>
        </xsl:if>

      </sect3>
    </xsl:template>

    <!-- Custom catalog -->
    <xsl:template match='Configuration/Extension/CustomCatalog' >
      <sect3><title>Custom Catalog: <xsl:value-of select='@id' /></title>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <!-- generate a list of catalogs and entries -->
        <xsl:apply-templates select='MessageSet'/>

      </sect3>
    </xsl:template>
    <xsl:template match='MessageSet' >
      <sect4><title>Message Catalog Entries (<xsl:value-of select='@language' />-<xsl:value-of select='@country' />)</title>
        <informaltable frame='all'>
          <tgroup cols='2' align='left' colsep='1' rowsep='1'>
            <colspec colname='entryID'/>
            <colspec colname='value'/>
            <thead>
              <row>
                <entry>Message Entry Identifier</entry>
                <entry>Message</entry>
              </row>
            </thead>
            <tbody>
              <xsl:apply-templates select='Msg'/>
            </tbody>
          </tgroup>
        </informaltable>
      </sect4>
    </xsl:template>
    <xsl:template match='Msg' >
      <row>
        <entry><xsl:value-of select='@id' /></entry>
        <entry><xsl:value-of select='.' /></entry>
      </row>
    </xsl:template>


    <!-- TASK SCHEDULE -->
    <xsl:template match='TaskSchedule' >
      <sect3><title>Task Schedule: <xsl:value-of select='@name' /></title>
        <xsl:if test='Description'>
          <literallayout><xsl:value-of select='Description' /></literallayout>
        </xsl:if>
        <para><emphasis>Task</emphasis>:  <xsl:value-of select='TaskDefinitionRef/ObjectRef/@name' /></para>
        <xsl:if test='@repetitionCount and @repetitionUnit'>
          <para><emphasis>Repetition</emphasis>: <xsl:value-of select='@repetitionCount' /> times each <xsl:value-of select='@repetitionUnit' /></para>
        </xsl:if>
        <para><emphasis>Disabled</emphasis>?  <xsl:choose><xsl:when test='@disabled = "true"'>Yes</xsl:when><xsl:otherwise>No</xsl:otherwise></xsl:choose></para>
        <xsl:if test='Variables/Object/Attribute[@name="task"]/Object/Attribute[@name = "taskName"]'>
          <para><emphasis>Filter on Deferred Task</emphasis>:  <xsl:value-of select='Variables/Object/Attribute[@name="task"]/Object/Attribute[@name = "taskName"]/@value' /></para>
        </xsl:if>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>

        <!-- TODO: extract host names -->

      </sect3>
    </xsl:template>





    <!-- USER -->
    <xsl:template match='User' >
      <sect3><title>User: <xsl:value-of select='@name' /></title>
        <!-- apply the descripton as comment template -->
        <xsl:apply-templates select='preceding-sibling::comment()' mode='description-as-comment' />

        <xsl:if test='UserForm'>
          <para><emphasis>User Form</emphasis>: <xsl:value-of select='UserForm/ObjectRef/@name' /></para>
        </xsl:if>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
        <!-- generate a list of admin groups -->
        <sect4><title>Administration Group Membership:</title>
          <itemizedlist>
            <xsl:apply-templates select='AdminGroups/ObjectRef'  mode='embedded'/>
          </itemizedlist>
        </sect4>
        <sect4><title>Controlled Organizations:</title>
          <itemizedlist>
            <xsl:apply-templates select='ControlledObjectGroups/ObjectRef' mode='embedded' />
          </itemizedlist>
        </sect4>
        <sect4><title>Member of Organizations:</title>
          <itemizedlist>
            <xsl:apply-templates select='MemberObjectGroups/ObjectRef' mode='embedded' />
          </itemizedlist>
        </sect4>
      </sect3>
    </xsl:template>

    <!-- OBJECT REF -->
    <xsl:template match='ObjectRef' mode='embedded'>
      <listitem><para><xsl:value-of select='@name' /></para></listitem>
    </xsl:template>


    <!-- USER FORM -->
    <xsl:template match='Configuration[@wstype="UserForm"]' >
      <sect3><title>User Form: <xsl:value-of select='@name' /></title>
        <xsl:if test='Extension/Form/Comments'>
          <literallayout><xsl:value-of select='Extension/Form/Comments' /></literallayout>
        </xsl:if>
        <para><emphasis>Path in CBE</emphasis>:  <xsl:value-of select='$fileName' /></para>
        <xsl:if test='count(Extension/Form/Include/ObjectRef) &gt; 0'>
          <sect4><title>Included Forms:</title>
            <itemizedlist>
              <xsl:apply-templates select='Extension/Form/Include/ObjectRef' mode='embedded' />
            </itemizedlist>
          </sect4>
        </xsl:if>
      </sect3>
    </xsl:template>


</xsl:stylesheet>
