home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _7F33671989944A0280F83E22A27EFF18 < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-20  |  37.1 KB  |  658 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!--  related-links.xsl 1.03; 2002 May 7
  3.  | DITA link processor (xref, related-links)
  4.  |
  5.  | Copyright IBM Corporation, 2002
  6.  | This file is part of the DITA package on IBM's developerWorks site.
  7.  | See license.txt for disclaimers.
  8.  *-->
  9. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  10.  
  11. <xsl:output method="xml"
  12.             encoding="iso-8859-1"
  13.             indent="yes"
  14.             doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  15.             doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  16. />
  17. <!--issues: can't eliminate dups or do adequate test for heading if conrefs present - not currently eliminating dups-->
  18.  
  19.  
  20. <xsl:template match="*[contains(@class,' topic/related-links ')]">
  21.    <span>
  22.     <xsl:call-template name="setclass"/>
  23.      <xsl:variable name="currentrole">
  24.           <xsl:choose>
  25.                <xsl:when test="@role"><xsl:value-of select="@role"/></xsl:when>
  26.                <xsl:otherwise>none</xsl:otherwise>
  27.           </xsl:choose>
  28.      </xsl:variable>
  29.      <xsl:variable name="currenttype">
  30.           <xsl:choose>
  31.                <xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
  32.                <xsl:otherwise>none</xsl:otherwise>
  33.           </xsl:choose>
  34.      </xsl:variable>
  35.  
  36.      <!--children-->
  37.      <xsl:if test="descendant-or-self::*[not(ancestor-or-self::linklist)][(ancestor-or-self::*/@role)[last()]='child']">
  38.      <dl>
  39.      <xsl:apply-templates select="*[contains(@class,' topic/link ')]|*[contains(@class,' topic/linkpool ')]">
  40.           <xsl:with-param name="procrole">child descendant</xsl:with-param>
  41.           <xsl:with-param name="parentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  42.      </xsl:apply-templates>
  43.      </dl>
  44.      </xsl:if>
  45.  
  46.      <!--todo: grab rel-link heading text from strings.xml-->
  47.      <!--related concepts-->
  48.      <xsl:if test="descendant-or-self::*[not(ancestor-or-self::*[contains(@class,' topic/linklist ')])][not((ancestor-or-self::*/@role)[last()]='child')][(ancestor-or-self::*/@type)[last()]='concept']">
  49.           <p>
  50.           <b>
  51.              <xsl:call-template name="getString">
  52.                   <xsl:with-param name="stringName" select="'Related concepts'"/>
  53.                </xsl:call-template>
  54.           </b><br class="br"/>
  55.      <xsl:call-template name="sort-links-by-role">
  56.           <xsl:with-param name="proctype">concept</xsl:with-param>
  57.           <xsl:with-param name="currentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  58.           <xsl:with-param name="currenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  59.      </xsl:call-template>
  60.           </p>
  61.      </xsl:if>
  62.  
  63.      <!--related tasks-->
  64.      <xsl:if test="descendant-or-self::*[not(ancestor-or-self::*[contains(@class,' topic/linklist ')])][not((ancestor-or-self::*/@role)[last()]='child')][(ancestor-or-self::*/@type)[last()]='task']">
  65.           <p>
  66.           <b>
  67.              <xsl:call-template name="getString">
  68.                   <xsl:with-param name="stringName" select="'Related tasks'"/>
  69.                </xsl:call-template>
  70.           </b><br class="br"/>
  71.      <xsl:call-template name="sort-links-by-role">
  72.           <xsl:with-param name="proctype">task</xsl:with-param>
  73.           <xsl:with-param name="currentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  74.           <xsl:with-param name="currenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  75.      </xsl:call-template>
  76.           </p>
  77.      </xsl:if>
  78.  
  79.  
  80.      <!--related reference-->
  81.      <xsl:if test="descendant-or-self::*[not(ancestor-or-self::*[contains(@class,' topic/linklist ')])][not((ancestor-or-self::*/@role)[last()]='child')][(ancestor-or-self::*/@type)[last()]='reference']">
  82.           <p>
  83.           <b>
  84.              <xsl:call-template name="getString">
  85.                   <xsl:with-param name="stringName" select="'Related reference'"/>
  86.                </xsl:call-template>
  87.           </b><br class="br"/>
  88.      <xsl:call-template name="sort-links-by-role">
  89.           <xsl:with-param name="proctype">reference</xsl:with-param>
  90.           <xsl:with-param name="currentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  91.           <xsl:with-param name="currenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  92.      </xsl:call-template>
  93.           </p>
  94.      </xsl:if>
  95.  
  96.      <!--other info-->
  97.      <xsl:if test="descendant::*[not(ancestor-or-self::*[contains(@class,' topic/linklist ')])]
  98. [not((ancestor-or-self::*/@role)[last()]='child')]
  99. [not((ancestor-or-self::*/@type)[last()]='concept')]
  100. [not((ancestor-or-self::*/@type)[last()]='task')]
  101. [not((ancestor-or-self::*/@type)[last()]='reference')]">
  102.           <p>
  103.           <b>
  104.              <xsl:call-template name="getString">
  105.                   <xsl:with-param name="stringName" select="'Related information'"/>
  106.                </xsl:call-template>
  107.           </b><br class="br"/>
  108.      <xsl:call-template name="sort-links-by-role">
  109.           <xsl:with-param name="proctype">catch-all</xsl:with-param>
  110.           <xsl:with-param name="currentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  111.           <xsl:with-param name="currenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  112.      </xsl:call-template>
  113.           </p>
  114.      </xsl:if>
  115.  
  116.  
  117.      <!--linklists-->
  118.      <xsl:apply-templates select="*[contains(@class,' topic/linklist ')]"/>
  119.    </span>
  120. </xsl:template>
  121.  
  122. <xsl:template match="*[contains(@class,' topic/link ')]">
  123.      <xsl:param name="procrole">none</xsl:param>
  124.      <xsl:param name="proctype">none</xsl:param>
  125.      <xsl:param name="parentrole">none</xsl:param>
  126.      <xsl:param name="parenttype">none</xsl:param>
  127.      <xsl:variable name="currentrole">
  128.           <xsl:choose>
  129.                <xsl:when test="@role"><xsl:value-of select="@role"/></xsl:when>
  130.                <xsl:otherwise><xsl:value-of select="$parentrole"/></xsl:otherwise>
  131.           </xsl:choose>
  132.      </xsl:variable>
  133.      <xsl:variable name="currenttype">
  134.           <xsl:choose>
  135.                <xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
  136.                <xsl:otherwise><xsl:value-of select="$parenttype"/></xsl:otherwise>
  137.           </xsl:choose>
  138.      </xsl:variable>
  139.      <xsl:choose>
  140.           <xsl:when test="contains($procrole,'child') and $currentrole='child'">
  141.                <xsl:call-template name="make-link"><xsl:with-param name="child">yes</xsl:with-param></xsl:call-template>
  142.           </xsl:when>
  143.           <xsl:when test="contains($procrole,$currentrole) and contains($proctype,$currenttype)"><xsl:call-template name="make-link"/></xsl:when>
  144.           <xsl:when test="contains($procrole,$currentrole) and $proctype='catch-all' and not($currentrole='child') and not($currenttype='concept') and not($currenttype='task') and not($currenttype='reference')"><xsl:call-template name="make-link"/></xsl:when>
  145.           <xsl:when test="$procrole='linklist'"><xsl:call-template name="make-link"/></xsl:when>
  146.           <xsl:otherwise/><!--do nothing - not appropriate to create link this pass through-->
  147.      </xsl:choose>
  148. </xsl:template>
  149.  
  150. <xsl:template match="*[contains(@class,' topic/linkpool ')]">
  151.      <xsl:param name="procrole">none</xsl:param>
  152.      <xsl:param name="proctype">none</xsl:param>
  153.      <xsl:param name="parentrole">none</xsl:param>
  154.      <xsl:param name="parenttype">none</xsl:param>
  155.      <xsl:variable name="currentrole">
  156.           <xsl:choose>
  157.                <xsl:when test="@role"><xsl:value-of select="@role"/></xsl:when>
  158.                <xsl:otherwise><xsl:value-of select="$parentrole"/></xsl:otherwise>
  159.           </xsl:choose>
  160.      </xsl:variable>
  161.      <xsl:variable name="currenttype">
  162.           <xsl:choose>
  163.                <xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
  164.                <xsl:otherwise><xsl:value-of select="$parenttype"/></xsl:otherwise>
  165.           </xsl:choose>
  166.      </xsl:variable>
  167.  
  168.      <xsl:apply-templates select="*[contains(@class,' topic/link ')]|*[contains(@class,' topic/linkpool ')]">
  169.           <xsl:with-param name="procrole"><xsl:value-of select="$procrole"/></xsl:with-param>
  170.           <xsl:with-param name="proctype"><xsl:value-of select="$proctype"/></xsl:with-param>
  171.           <xsl:with-param name="parentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  172.           <xsl:with-param name="parenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  173.      </xsl:apply-templates>
  174.  
  175. </xsl:template>
  176.  
  177. <xsl:template name="sort-links-by-role">
  178.      <xsl:param name="proctype">none</xsl:param>
  179.      <xsl:param name="currentrole">none</xsl:param>
  180.      <xsl:param name="currenttype">none</xsl:param>
  181.      <xsl:apply-templates select="*[contains(@class,' topic/link ')]|*[contains(@class,' topic/linkpool ')]">
  182.           <xsl:with-param name="procrole">ancestor parent</xsl:with-param>
  183.           <xsl:with-param name="parentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  184.           <xsl:with-param name="proctype"><xsl:value-of select="$proctype"/></xsl:with-param>
  185.           <xsl:with-param name="parenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  186.      </xsl:apply-templates>
  187.      <xsl:apply-templates select="*[contains(@class,' topic/link ')]|*[contains(@class,' topic/linkpool ')]">
  188.           <xsl:with-param name="procrole">next previous sibling</xsl:with-param>
  189.           <xsl:with-param name="parentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  190.           <xsl:with-param name="proctype"><xsl:value-of select="$proctype"/></xsl:with-param>
  191.           <xsl:with-param name="parenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  192.      </xsl:apply-templates>
  193.      <xsl:apply-templates select="*[contains(@class,' topic/link ')]|*[contains(@class,' topic/linkpool ')]">
  194.           <xsl:with-param name="procrole">friend cousin sample other none</xsl:with-param>
  195.           <xsl:with-param name="parentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  196.           <xsl:with-param name="proctype"><xsl:value-of select="$proctype"/></xsl:with-param>
  197.           <xsl:with-param name="parenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  198.      </xsl:apply-templates>
  199.      <xsl:apply-templates select="*[contains(@class,' topic/link ')]|*[contains(@class,' topic/linkpool ')]">
  200.           <xsl:with-param name="procrole">external</xsl:with-param>
  201.           <xsl:with-param name="parentrole"><xsl:value-of select="$currentrole"/></xsl:with-param>
  202.           <xsl:with-param name="proctype"><xsl:value-of select="$proctype"/></xsl:with-param>
  203.           <xsl:with-param name="parenttype"><xsl:value-of select="$currenttype"/></xsl:with-param>
  204.      </xsl:apply-templates>
  205. </xsl:template>
  206.  
  207. <xsl:template name="make-link">
  208.   <xsl:param name="child">no</xsl:param>
  209.   <xsl:variable name="file">
  210.   <xsl:choose>
  211.      <xsl:when test="starts-with(@href,'http://')"><xsl:value-of select="@href"/></xsl:when>
  212.      <xsl:when test="starts-with(@href,'http://') and contains(@href,'#')"><xsl:value-of select="substring-before(@href,'#')"/></xsl:when>
  213.      <xsl:when test="contains(@href,'#')"><xsl:value-of select="$WORKDIR"/><xsl:value-of select="substring-before(@href,'#')"/></xsl:when>
  214.      <xsl:otherwise><xsl:value-of select="$WORKDIR"/><xsl:value-of select="@href"/></xsl:otherwise>
  215.   </xsl:choose>
  216.   </xsl:variable>
  217.  
  218.   <xsl:variable name="topicid">
  219.      <xsl:choose>
  220.           <xsl:when test="contains(@href,'#')"><xsl:value-of select="substring-after(@href,'#')"/></xsl:when>
  221.           <xsl:otherwise>none</xsl:otherwise>
  222.      </xsl:choose>
  223.   </xsl:variable>
  224.  
  225.   <xsl:variable name="topicpos">
  226.   <xsl:choose>
  227.      <xsl:when test="starts-with(@href,'#')">samefile</xsl:when>
  228.      <xsl:when test="contains(@href,'#')">otherfile</xsl:when>
  229.      <xsl:otherwise>firstinfile</xsl:otherwise>
  230.   </xsl:choose>
  231.   </xsl:variable>
  232.  
  233.   <xsl:variable name="topictype">
  234.      <xsl:choose>
  235.           <xsl:when test="@type='other'"><xsl:value-of select="@othertype"/></xsl:when>
  236.           <xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
  237.           <xsl:otherwise>topic</xsl:otherwise>
  238.      </xsl:choose>
  239.   </xsl:variable>
  240.  
  241.   <xsl:variable name="classval"><xsl:text> </xsl:text><xsl:value-of select="$topictype"/>/<xsl:value-of select="$topictype"/><xsl:text> </xsl:text></xsl:variable>
  242.  
  243.  
  244.   <xsl:choose>
  245.      <xsl:when test="$child='yes'">
  246.  
  247.           <dt><a>
  248.                <xsl:call-template name="setclass"/>
  249.                <xsl:attribute name="href">
  250.                     <xsl:choose>
  251.                          <xsl:when test="@type='external'"><xsl:value-of select="@href"/></xsl:when>
  252.                          <xsl:when test="starts-with(@href,'#')"><xsl:value-of select="@href"/></xsl:when>
  253.                          <xsl:when test="contains(@href,'.xml')">
  254.                               <xsl:value-of select="substring-before(@href,'.xml')"/>.<xsl:value-of select="$OUTEXT"/><xsl:value-of select="substring-after(@href,'.xml')"/>
  255.                          </xsl:when>
  256.                          <xsl:when test="contains(@href,'.dita')">
  257.                               <xsl:value-of select="substring-before(@href,'.dita')"/>.<xsl:value-of select="$OUTEXT"/><xsl:value-of select="substring-after(@href,'.dita')"/>
  258.                          </xsl:when>
  259.                          <xsl:otherwise>
  260.                  <xsl:call-template name="output-message">
  261.                    <xsl:with-param name="msg">Unknown file extension. If this is a link to an external resource, set type="external". If it's a link to a DITA resource, the file extension must be .dita or .xml .</xsl:with-param>
  262.                    <xsl:with-param name="msgnum">030</xsl:with-param>
  263.                    <xsl:with-param name="msgsev">E</xsl:with-param>
  264.                  </xsl:call-template>
  265.                          </xsl:otherwise>
  266.                     </xsl:choose>
  267.                </xsl:attribute>
  268.           <xsl:call-template name="get-link-text">
  269.           <xsl:with-param name="file"><xsl:value-of select="$file"/></xsl:with-param>
  270.           <xsl:with-param name="topicid"><xsl:value-of select="$topicid"/></xsl:with-param>
  271.           <xsl:with-param name="topictype"><xsl:value-of select="$topictype"/></xsl:with-param>
  272.           <xsl:with-param name="topicpos"><xsl:value-of select="$topicpos"/></xsl:with-param>
  273.           <xsl:with-param name="classval"><xsl:value-of select="$classval"/></xsl:with-param>
  274.           </xsl:call-template></a></dt>
  275.  
  276.           <dd><xsl:call-template name="get-link-shortdesc">
  277.           <xsl:with-param name="file"><xsl:value-of select="$file"/></xsl:with-param>
  278.           <xsl:with-param name="topicid"><xsl:value-of select="$topicid"/></xsl:with-param>
  279.           <xsl:with-param name="topictype"><xsl:value-of select="$topictype"/></xsl:with-param>
  280.           <xsl:with-param name="topicpos"><xsl:value-of select="$topicpos"/></xsl:with-param>
  281.           <xsl:with-param name="classval"><xsl:value-of select="$classval"/></xsl:with-param>
  282.           </xsl:call-template></dd>
  283.  
  284.      </xsl:when>
  285.      <xsl:otherwise>
  286.           <a>
  287.              <xsl:call-template name="setclass"/>
  288.                <xsl:attribute name="href">
  289.                     <xsl:choose>
  290.                          <xsl:when test="@type='external'"><xsl:value-of select="@href"/></xsl:when>
  291.                          <xsl:when test="starts-with(@href,'#')"><xsl:value-of select="@href"/></xsl:when>
  292.                          <xsl:when test="contains(@href,'.xml')">
  293.                               <xsl:value-of select="substring-before(@href,'.xml')"/>.<xsl:value-of select="$OUTEXT"/><xsl:value-of select="substring-after(@href,'.xml')"/>
  294.                          </xsl:when>
  295.                          <xsl:when test="contains(@href,'.dita')">
  296.                               <xsl:value-of select="substring-before(@href,'.dita')"/>.<xsl:value-of select="$OUTEXT"/><xsl:value-of select="substring-after(@href,'.dita')"/>
  297.                          </xsl:when>
  298.                          <xsl:otherwise>
  299.                  <xsl:call-template name="output-message">
  300.                    <xsl:with-param name="msg">Unknown file extension. If this is a link to an external resource, set type="external". If it's a link to a DITA resource, the file extension must be .dita or .xml .</xsl:with-param>
  301.                    <xsl:with-param name="msgnum">031</xsl:with-param>
  302.                    <xsl:with-param name="msgsev">E</xsl:with-param>
  303.                  </xsl:call-template>
  304.                           </xsl:otherwise>
  305.                     </xsl:choose>
  306.                </xsl:attribute>
  307.           <xsl:attribute name="title">
  308.               <xsl:call-template name="get-link-shortdesc">
  309.                <xsl:with-param name="file"><xsl:value-of select="$file"/></xsl:with-param>
  310.                <xsl:with-param name="topicid"><xsl:value-of select="$topicid"/></xsl:with-param>
  311.                <xsl:with-param name="topictype"><xsl:value-of select="$topictype"/></xsl:with-param>
  312.                <xsl:with-param name="topicpos"><xsl:value-of select="$topicpos"/></xsl:with-param>
  313.                <xsl:with-param name="classval"><xsl:value-of select="$classval"/></xsl:with-param>
  314.               </xsl:call-template>
  315.           </xsl:attribute>
  316.           <xsl:call-template name="get-link-text">
  317.                <xsl:with-param name="file"><xsl:value-of select="$file"/></xsl:with-param>
  318.                <xsl:with-param name="topicid"><xsl:value-of select="$topicid"/></xsl:with-param>
  319.                <xsl:with-param name="topictype"><xsl:value-of select="$topictype"/></xsl:with-param>
  320.                <xsl:with-param name="topicpos"><xsl:value-of select="$topicpos"/></xsl:with-param>
  321.                <xsl:with-param name="classval"><xsl:value-of select="$classval"/></xsl:with-param>
  322.           </xsl:call-template></a><br class="br"/>
  323.      </xsl:otherwise>
  324.   </xsl:choose>
  325.  
  326. </xsl:template>
  327.  
  328. <xsl:template name="get-link-text">
  329.      <xsl:param name="file">file</xsl:param>
  330.      <xsl:param name="topicid">topicid</xsl:param>
  331.      <xsl:param name="topictype">topictype</xsl:param>
  332.      <xsl:param name="topicpos">topicposition</xsl:param>
  333.      <xsl:param name="classval">class value</xsl:param>
  334.      <xsl:choose>
  335.           <xsl:when test="*[contains(@class,' topic/linktext ')]"><xsl:value-of select="*[contains(@class,' topic/linktext ')]"/></xsl:when>
  336.           <xsl:when test="@type='external'"><xsl:value-of select="@href"/></xsl:when>
  337.           <xsl:when test="$topicpos='samefile'">
  338.             <xsl:choose>
  339.                <xsl:when test="//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/title ')]">
  340.                <xsl:value-of select="normalize-space(//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/title ')])"/>
  341.                </xsl:when>
  342.                <xsl:otherwise>***
  343.          <xsl:call-template name="output-message">
  344.            <xsl:with-param name="msg">Unable to retrieve link text from target (topic in same file). Make sure the link type matches the target, and that the topic id is correct.</xsl:with-param>
  345.            <xsl:with-param name="msgnum">032</xsl:with-param>
  346.            <xsl:with-param name="msgsev">E</xsl:with-param>
  347.          </xsl:call-template>
  348.            </xsl:otherwise>
  349.             </xsl:choose>
  350.           </xsl:when>
  351.                 <xsl:when test="$topicpos='firstinfile'">
  352.             <xsl:choose>
  353.                <xsl:when test="document($file)//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/title ')]">
  354.                <xsl:value-of select="normalize-space(document($file)//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/title ')])"/>
  355.                </xsl:when>
  356.                <xsl:otherwise>***
  357.          <xsl:call-template name="output-message">
  358.            <xsl:with-param name="msg">Unable to retrieve link text from target (first topic in target file). Make sure the link type matches the target. If the target is not accessible at build time, define the link text in the link.</xsl:with-param>
  359.            <xsl:with-param name="msgnum">033</xsl:with-param>
  360.            <xsl:with-param name="msgsev">E</xsl:with-param>
  361.          </xsl:call-template>
  362.            </xsl:otherwise>
  363.             </xsl:choose>
  364.           </xsl:when>
  365.           <xsl:when test="$topicpos='otherfile'">
  366.             <xsl:choose>
  367.                <xsl:when test="document($file)//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/title ')]">
  368.                <xsl:value-of select="normalize-space(document($file)//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/title ')])"/>
  369.                </xsl:when>
  370.                <xsl:otherwise>***
  371.          <xsl:call-template name="output-message">
  372.            <xsl:with-param name="msg">Unable to retrieve link text from target (topic in another file). Make sure the link type matches the target, and that the topic id is correct. If the target is not accessible at build time, define the link text in the link.</xsl:with-param>
  373.            <xsl:with-param name="msgnum">034</xsl:with-param>
  374.            <xsl:with-param name="msgsev">E</xsl:with-param>
  375.          </xsl:call-template>
  376.            </xsl:otherwise>
  377.             </xsl:choose>
  378.           </xsl:when>
  379.           <xsl:otherwise>
  380.          <xsl:call-template name="output-message">
  381.            <xsl:with-param name="msg">Problem with link text retrieval. Check that the href attribute is correctly formed.<!--this error msg should never appear, since all three vals for topicpos are tested, but including for completeness--></xsl:with-param>
  382.            <xsl:with-param name="msgnum">035</xsl:with-param>
  383.            <xsl:with-param name="msgsev">E</xsl:with-param>
  384.          </xsl:call-template>
  385.       </xsl:otherwise>
  386.      </xsl:choose>
  387. </xsl:template>
  388.  
  389. <xsl:template name="get-link-shortdesc">
  390.      <xsl:param name="file">file</xsl:param>
  391.      <xsl:param name="topicid">file</xsl:param>
  392.      <xsl:param name="topictype">file</xsl:param>
  393.      <xsl:param name="topicpos">topicposition</xsl:param>
  394.      <xsl:param name="classval">class value</xsl:param>
  395.      <xsl:choose>
  396.           <xsl:when test="*[contains(@class,' topic/desc ')]"><xsl:value-of select="*[contains(@class,' topic/desc ')]"/></xsl:when>
  397.       <xsl:when test="@type='external'"/><!--do nothing - no way to get desc from external source-->
  398.           <xsl:when test="$topicpos='samefile'">
  399.         <xsl:choose>
  400.             <xsl:when test="//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/shortdesc ')]">
  401.                        <xsl:value-of select="normalize-space(//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/shortdesc ')])"/>
  402.             </xsl:when>
  403.             <xsl:otherwise>
  404.              <xsl:call-template name="output-message">
  405.                <xsl:with-param name="msg">Unable to retrieve short description from target (topic in same file). Make sure the link type matches the target, and that the topic id is correct.</xsl:with-param>
  406.                <xsl:with-param name="msgnum">036</xsl:with-param>
  407.                <xsl:with-param name="msgsev">E</xsl:with-param>
  408.              </xsl:call-template>
  409.             </xsl:otherwise>
  410.         </xsl:choose>        
  411.           </xsl:when>
  412.                 <xsl:when test="$topicpos='firstinfile'">
  413.         <xsl:choose>
  414.             <xsl:when test="document($file)//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/shortdesc ')]">
  415.                        <xsl:value-of select="normalize-space(document($file)//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/shortdesc ')])"/>
  416.             </xsl:when>
  417.             <xsl:otherwise>
  418.              <xsl:call-template name="output-message">
  419.                <xsl:with-param name="msg">Unable to retrieve short description from target (first topic in target file). Make sure the link type matches the target. If the target is not accessible at build time or does not have a short description, define the description in the link.</xsl:with-param>
  420.                <xsl:with-param name="msgnum">037</xsl:with-param>
  421.                <xsl:with-param name="msgsev">E</xsl:with-param>
  422.              </xsl:call-template>
  423.             </xsl:otherwise>
  424.         </xsl:choose>        
  425.            </xsl:when>
  426.           <xsl:when test="$topicpos='otherfile'">
  427.         <xsl:choose>
  428.             <xsl:when test="document($file)//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/shortdesc ')]">
  429.                        <xsl:value-of select="normalize-space(document($file)//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/shortdesc ')])"/>
  430.             </xsl:when>
  431.             <xsl:otherwise>
  432.              <xsl:call-template name="output-message">
  433.                <xsl:with-param name="msg">Unable to retrieve short description from target (topic in another file). Make sure the link type matches the target, and that the topic id is correct. If the target is not accessible at build time or does not have a short description, define the description in the link.</xsl:with-param>
  434.                <xsl:with-param name="msgnum">038</xsl:with-param>
  435.                <xsl:with-param name="msgsev">E</xsl:with-param>
  436.              </xsl:call-template>
  437.             </xsl:otherwise>
  438.         </xsl:choose>        
  439.           </xsl:when>
  440.           <xsl:otherwise>
  441.          <xsl:call-template name="output-message">
  442.            <xsl:with-param name="msg">Problem with link description retrieval. Check that the href attribute is correctly formed.<!--this error msg should never appear, since all three vals for topicpos are tested, but including for completeness--></xsl:with-param>
  443.            <xsl:with-param name="msgnum">039</xsl:with-param>
  444.            <xsl:with-param name="msgsev">E</xsl:with-param>
  445.          </xsl:call-template>
  446.       </xsl:otherwise>
  447.      </xsl:choose>
  448. </xsl:template>
  449.  
  450.  
  451. <xsl:template match="*[contains(@class,' topic/xref ')]">
  452.   <xsl:variable name="file">
  453.   <xsl:choose>
  454.      <xsl:when test="contains(@href,'#')"><xsl:value-of select="$WORKDIR"/><xsl:value-of select="substring-before(@href,'#')"/></xsl:when>
  455.      <xsl:otherwise><xsl:value-of select="$WORKDIR"/><xsl:value-of select="@href"/></xsl:otherwise>
  456.   </xsl:choose>
  457.   </xsl:variable>
  458.  
  459.   <xsl:variable name="topicid">
  460.   <xsl:choose>
  461.      <xsl:when test="contains(@href,'#') and contains(substring-after(@href,'#'),'/')"><xsl:value-of select="substring-before(substring-after(@href,'#'),'/')"/></xsl:when>
  462.      <xsl:when test="contains(@href,'#')"><xsl:value-of select="substring-after(@href,'#')"/></xsl:when>
  463.      <xsl:otherwise>none</xsl:otherwise>
  464.   </xsl:choose>
  465.   </xsl:variable>
  466.  
  467.   <xsl:variable name="elemid">
  468.     <xsl:choose>
  469.      <xsl:when test="contains(@href,'#') and contains(substring-after(@href,'#'),'/')"><xsl:value-of select="substring-after(substring-after(@href,'#'),'/')"/></xsl:when>
  470.      <xsl:otherwise>none</xsl:otherwise>
  471.     </xsl:choose>
  472.   </xsl:variable>
  473.  
  474.   <xsl:variable name="topicpos">
  475.   <xsl:choose>
  476.      <xsl:when test="starts-with(@href,'#')">samefile</xsl:when>
  477.      <xsl:when test="contains(@href,'#')">otherfile</xsl:when>
  478.      <xsl:otherwise>firstinfile</xsl:otherwise>
  479.   </xsl:choose>
  480.   </xsl:variable>
  481.  
  482.   <xsl:variable name="targettype">
  483.      <xsl:choose>
  484.           <xsl:when test="@type='other'"><xsl:value-of select="@othertype"/></xsl:when>
  485.           <xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
  486.           <xsl:otherwise>topic</xsl:otherwise>
  487.      </xsl:choose>
  488.   </xsl:variable>
  489.  
  490.  
  491.   <xsl:variable name="classval">
  492.      <xsl:choose>
  493.           <xsl:when test="@type='fig' or @type='figgroup' or @type='table' or @type='section' or @type='li' or @type='fn'"><xsl:text> </xsl:text>topic/<xsl:value-of select="$targettype"/><xsl:text> </xsl:text></xsl:when>
  494.           <xsl:otherwise><xsl:text> </xsl:text><xsl:value-of select="$targettype"/>/<xsl:value-of select="$targettype"/><xsl:text> </xsl:text></xsl:otherwise>
  495.      </xsl:choose>
  496.   </xsl:variable>
  497.  
  498.   <a>
  499.     <xsl:call-template name="setclass"/>
  500.      <xsl:attribute name="href">
  501.           <xsl:choose>
  502.                <xsl:when test="@type='external'"><xsl:value-of select="@href"/></xsl:when>
  503.                <xsl:when test="starts-with(@href,'#')">#<xsl:value-of select="$topicid"/><xsl:if test="contains(substring-after(@href,'#'),'/')">__<xsl:value-of select="$elemid"/></xsl:if>
  504.            </xsl:when>
  505.                <xsl:when test="contains(@href,'.xml')">
  506.                     <xsl:value-of select="substring-before(@href,'.xml')"/>.<xsl:value-of select="$OUTEXT"/><xsl:if test="contains(@href,'#')">#<xsl:value-of select="$topicid"/></xsl:if><xsl:if test="contains(substring-after(@href,'#'),'/')">__<xsl:value-of select="$elemid"/></xsl:if>
  507.                </xsl:when>
  508.                <xsl:when test="contains(@href,'.dita')">
  509.                     <xsl:value-of select="substring-before(@href,'.dita')"/>.<xsl:value-of select="$OUTEXT"/><xsl:if test="contains(@href,'#')">#<xsl:value-of select="$topicid"/></xsl:if><xsl:if test="contains(substring-after(@href,'#'),'/')">__<xsl:value-of select="$elemid"/></xsl:if>
  510.                </xsl:when>
  511.                <xsl:otherwise>
  512.              <xsl:call-template name="output-message">
  513.                <xsl:with-param name="msg">Unknown file extension. If this is a link to an external resource, set type="external". If it's a link to a DITA resource, the file extension must be .dita or .xml .</xsl:with-param>
  514.                <xsl:with-param name="msgnum">040</xsl:with-param>
  515.                <xsl:with-param name="msgsev">E</xsl:with-param>
  516.              </xsl:call-template>
  517.                 </xsl:otherwise>
  518.           </xsl:choose>
  519.      </xsl:attribute>
  520.   <xsl:choose>
  521.      <xsl:when test="*|text()"><xsl:value-of select="."/></xsl:when>
  522.      <xsl:when test="@type='external'"><xsl:value-of select="@href"/></xsl:when>
  523.      <xsl:when test="$targettype='fig' or $targettype='figgroup' or $targettype='table' or $targettype='section'">
  524.        <xsl:choose>
  525.           <xsl:when test="$topicpos='samefile' and //*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]/*[contains(@class,' topic/title ')]">
  526.                <xsl:value-of select="normalize-space(//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]/*[contains(@class,' topic/title ')])"/>
  527.           </xsl:when>
  528.           <xsl:when test="$topicpos='otherfile' and document($file)//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]/*[contains(@class,' topic/title ')]">
  529.                <xsl:value-of select="normalize-space(document($file)//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]/*[contains(@class,' topic/title ')])"/>
  530.           </xsl:when>
  531.           <xsl:otherwise>***
  532.          <xsl:call-template name="output-message">
  533.            <xsl:with-param name="msg">Unable to retrieve link text from target. Make sure the link type matches the target, the ids for topic and element are correct, and that the target has a title. If the target is not accessible at build time, or does not have a title, give the link text as content of the xref element.</xsl:with-param>
  534.            <xsl:with-param name="msgnum">041</xsl:with-param>
  535.            <xsl:with-param name="msgsev">E</xsl:with-param>
  536.          </xsl:call-template>
  537.       </xsl:otherwise>
  538.        </xsl:choose>
  539.      </xsl:when>
  540.      <xsl:when test="$targettype='li'">
  541.        <xsl:choose>
  542.           <xsl:when test="$topicpos='samefile' and //*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]">
  543.                <xsl:apply-templates mode="xref" select="//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]"/>
  544.           </xsl:when>
  545.           <xsl:when test="$topicpos='otherfile' and document($file)//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]">
  546.                <xsl:apply-templates mode="xref" select="document($file)//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ')]//*[contains(@class, $classval)][@id=$elemid]"/>
  547.           </xsl:when>
  548.           <xsl:otherwise>***
  549.          <xsl:call-template name="output-message">
  550.            <xsl:with-param name="msg">Unable to find the target to determine the list item number. Make sure the link type matches the target, and that the ids for topic and element are correct.</xsl:with-param>
  551.            <xsl:with-param name="msgnum">042</xsl:with-param>
  552.            <xsl:with-param name="msgsev">E</xsl:with-param>
  553.          </xsl:call-template>
  554.       </xsl:otherwise>
  555.        </xsl:choose>
  556.      </xsl:when>
  557.      <xsl:when test="$targettype='fn'">
  558.           <!--??? what do I do here?-->
  559.          <xsl:call-template name="output-message">
  560.            <xsl:with-param name="msg">Linking to footnotes not currently supported.</xsl:with-param>
  561.            <xsl:with-param name="msgnum">043</xsl:with-param>
  562.            <xsl:with-param name="msgsev">E</xsl:with-param>
  563.          </xsl:call-template>
  564.      </xsl:when>
  565.      <xsl:otherwise><!--topic-->
  566.        <xsl:choose>
  567.           <xsl:when test="$topicpos='samefile'">
  568.             <xsl:choose>
  569.                <xsl:when test="//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class,' topic/title ')]">
  570.                <xsl:value-of select="normalize-space(//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class,' topic/title ')])"/>
  571.                </xsl:when>
  572.                <xsl:otherwise>***
  573.          <xsl:call-template name="output-message">
  574.            <xsl:with-param name="msg">Unable to retrieve link text from target (topic in same file). Make sure the link type matches the target, and that the id for the topic is correct.</xsl:with-param>
  575.            <xsl:with-param name="msgnum">044</xsl:with-param>
  576.            <xsl:with-param name="msgsev">E</xsl:with-param>
  577.          </xsl:call-template>
  578.            </xsl:otherwise>
  579.             </xsl:choose>
  580.           </xsl:when>
  581.              <xsl:when test="$topicpos='firstinfile'">
  582.             <xsl:choose>
  583.                <xsl:when test="document($file)//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/title ')]">
  584.                <xsl:value-of select="normalize-space(document($file)//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/title ')])"/>
  585.                </xsl:when>
  586.                <xsl:otherwise>***
  587.          <xsl:call-template name="output-message">
  588.            <xsl:with-param name="msg">Unable to retrieve link text from target (first topic in target file). Make sure the link type matches the target, which is the first topic in the referenced file, and that the referenced file is accessible. If the target is not accessible at build time, give the link text as content of the xref element.</xsl:with-param>
  589.            <xsl:with-param name="msgnum">045</xsl:with-param>
  590.            <xsl:with-param name="msgsev">E</xsl:with-param>
  591.          </xsl:call-template>
  592.            </xsl:otherwise>
  593.             </xsl:choose>
  594.           </xsl:when>
  595.           <xsl:when test="$topicpos='otherfile'">
  596.             <xsl:choose>
  597.                <xsl:when test="document($file)//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/title ')]">
  598.                <xsl:value-of select="normalize-space(document($file)//*[contains(@class, $classval)][@id=$topicid]/*[contains(@class, ' topic/title ')])"/>
  599.                </xsl:when>
  600.                <xsl:otherwise>***
  601.          <xsl:call-template name="output-message">
  602.            <xsl:with-param name="msg">Unable to retrieve link text from target (topic in target file). Make sure the link type matches the target, that the id for the topic is correct, and that the file is accessible. If the target is not accessible at build time, give the link text as content of the xref element.</xsl:with-param>
  603.            <xsl:with-param name="msgnum">046</xsl:with-param>
  604.            <xsl:with-param name="msgsev">E</xsl:with-param>
  605.          </xsl:call-template>
  606.            </xsl:otherwise>
  607.             </xsl:choose>
  608.           </xsl:when>
  609.           <xsl:otherwise>
  610.          <xsl:call-template name="output-message">
  611.            <xsl:with-param name="msg">Unable to retrieve link text from target. Make sure the href is correctly formed and can be used to reach the target. If the target is not a DITA resource, make sure type="external" is set. If the target is not accessible at build time, give the link text as content of the xref element.</xsl:with-param>
  612.            <xsl:with-param name="msgnum">047</xsl:with-param>
  613.            <xsl:with-param name="msgsev">E</xsl:with-param>
  614.          </xsl:call-template>
  615.       </xsl:otherwise>
  616.        </xsl:choose>
  617.      </xsl:otherwise>
  618.   </xsl:choose>
  619.   </a>
  620.  
  621.  
  622. </xsl:template>
  623.  
  624. <xsl:template match="*[contains(@class,' topic/linklist ')]">
  625.    <xsl:choose>
  626.      <xsl:when test="parent::*[contains(@class,' topic/related-links ')]">
  627.           <p>
  628.           <xsl:call-template name="setclass"/>
  629.           <xsl:call-template name="makelinklist"/>
  630.           </p>
  631.      </xsl:when>
  632.      <xsl:otherwise>
  633.           <blockquote>
  634.                <xsl:call-template name="setclass"/>
  635.                <xsl:call-template name="makelinklist"/>
  636.           </blockquote>
  637.      </xsl:otherwise>
  638.   </xsl:choose>
  639. </xsl:template>
  640.  
  641. <xsl:template name="makelinklist">
  642.   <xsl:apply-templates select="*[contains(@class, ' topic/title ')]"/>
  643.   <xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/>
  644.   <xsl:apply-templates select="*[contains(@class,' topic/linklist ')]|*[contains(@class,' topic/link ')]"><xsl:with-param name="procrole">linklist</xsl:with-param></xsl:apply-templates>
  645. </xsl:template>
  646.  
  647.  
  648. <xsl:template match="*[contains(@class, ' topic/linklist ')]/*[contains(@class, ' topic/title ')]">
  649.   <b><xsl:apply-templates/></b><br class="br"/>
  650. </xsl:template>
  651.  
  652. <xsl:template match="*[contains(@class, ' topic/linklist ')]/*[contains(@class, ' topic/desc ')]">
  653.   <xsl:apply-templates/><br class="br"/>
  654. </xsl:template>
  655.  
  656. </xsl:stylesheet>
  657.  
  658.