Fixed typo in map tree view

Fixed typo in map tree view

(:~
 : DITA for Small Teams
 :
 : Link management application RESTXQ implementation.
 :
 : Copyright (c) 2015 DITA for Small Teams (dita-for-small-teams.org)
 :
 : See the BaseX RESTXQ documentation for details on how the RESTXQ
 : mechanism works.
 :
 :)
module namespace linkmgr='http://basex.org/modules/linkmgr';

import module namespace bxutil="http://dita-for-small-teams.org/xquery/modules/basex-utils";
import module namespace linkutil="http://dita-for-small-teams.org/xquery/modules/linkmgmt-utils";
import module namespace df="http://dita-for-small-teams.org/xquery/modules/dita-utils";

declare
  %rest:path("/linkmgr/maptreeView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:maptreeView($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $map := doc($docURI)
   let $tree := df:getMapTree($map)
   return

      <title>Map Tree for {df:getTitleText($map/*)}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Map Tree for "{df:getTitleText($map/*)}"

      {linkmgr:reportDocDetails($map)}

       {
        linkmgr:treeToHtml($tree)
       }

};

declare
  %rest:path("/linkmgr/navtreeView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:navtreeView($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $map := doc($docURI)
   let $tree := linkmgr:getMapNavTree($map)
   return

      <title>Nav Tree for {df:getTitleText($map/*)}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Navigation Tree for "{df:getTitleText($map/*)}"

      {linkmgr:reportDocDetails($map)}

       { $tree }

};

(:~
 : Document source view
 :)
declare
  %rest:path("/linkmgr/docview/{$docURI=.+}/src")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewSource($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Source for Document {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Source for Document "{$title}"

      {linkmgr:reportDocDetails($doc)}

        {serialize($doc)}

};

(:~
 : Document dependency view
 :)
declare
  %rest:path("/linkmgr/dependencyView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewDependencies($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Dependencies for Document {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Dependencies for Document "{$title}"

      {linkmgr:reportDocDetails($doc)}

Content references

List of content references goes here

      { if (df:isMap($doc))
           then linkmgr:listMapDependencies($doc)
           else linkmgr:listTopicDependencies($doc)
      }

};

(:~
 : Document where-used view
 :)
declare
  %rest:path("/linkmgr/whereUsedView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewWhereUsed($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Where-Used Report for Document {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Where-Used Report for Document "{$title}"

      {linkmgr:reportDocDetails($doc)}

Users of This Document

List of documents that have some form of pointer to this document.

      { if (df:isMap($doc))
           then linkmgr:listMapWhereUsed($doc)
           else linkmgr:listTopicWhereUsed($doc)
      }

};

declare function linkmgr:listMapWhereUsed($doc as document-node()) as node()* {

Used As a Submap

List of maps that use this map as a submap. Indicates
        whether the use is direct or indirect.

Used as a Peer Map

List of maps that make a peer map reference to this map

Used Via Peer Key Reference

List of documents (maps and topics) that make a peer-map reference to this map.

External-Scope Resources

List of external-scope resources goes here

};

declare function linkmgr:listTopicWhereUsed($doc as document-node()) as node()* {

Used As a Submap

List of maps that use this map as a submap. Indicates
        whether the use is direct or indirect.

Used as a Peer Map

List of maps that make a peer map reference to this map

Used Via Peer Key Reference

List of documents (maps and topics) that make a peer-map reference to this map.

External-Scope Resources

List of external-scope resources goes here

};

declare function linkmgr:listMapDependencies($doc as document-node()) as node()* {

DITA Topics

List of dita topics used from this map

DITA Maps

List of dita topics used from this map

Local-Scope Non-DITA Resources

List of local-scope non-DITA resources goes here

External-Scope Resources

List of external-scope resources goes here

};

declare function linkmgr:listTopicDependencies($doc as document-node()) as node()* {

Image References

List of referenced images goes here

Cross references

List of cross references goes here

Related Links

List of related links goes here

};

(:~
 : Document relationship table view
 :)
declare
  %rest:path("/linkmgr/reltableView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewReltables($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Relationship Tables for Map {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Relationship Tables for Map "{$title}"

      {linkmgr:reportDocDetails($doc)}

Reltables

Relationship tables go here

};

(:~
 : Document relationship table view
 :)
declare
  %rest:path("/linkmgr/keyspaceView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewKeyspaces($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Key Spaces for Map {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Key Spaces for Map "{$title}"

      {linkmgr:reportDocDetails($doc)}

Key Spaces

Key spaces go here

};

(:~
 : Constructs an HTML report of the details about a document
 :)
declare function linkmgr:reportDocDetails($doc as document-node()) as node()* {
   let $docURI := bxutil:getPathForDoc($doc)
   let $repo as xs:string := bxutil:getGitRepoForDoc($doc)
   let $branch as xs:string := bxutil:getGitBranchForDoc($doc)
   let $isDITA as xs:boolean := df:isDitaDoc($doc)
   return

URI: {linkmgr:makeLinkToDocSource(document-uri($doc))}

Branch: {$repo}/{$branch}

Is DITA: {$isDITA}

};

(:~
 : Takes a generic tree XML structure and generates appropriate HTML
 : markup for it.
 :
 : A tree consists of a sequence of <treeItem> elements, where each tree item
 : has the structure:
 :
 : <treeItem>
 :   label text
 :   <properties>
 :    <prop name="name">value</prop>
 :   </properties>
 :   <children>
 :    <treeItem>
 :   </children>
 : </treeItem>
 :)
declare function linkmgr:treeToHtml($tree as element(mapTree)) as node()* {

{
      for $treeItem in $tree/*
          return linkmgr:treeItemToHtml($treeItem)
    }

};

declare function linkmgr:makeLinkToDocSource($docURI as xs:string) as node()* {
     if ($docURI != '')
       then {bxutil:getPathForDocURI($docURI)}
       else $docURI
};

declare function linkmgr:treeItemToHtml($treeItem as element()) as node()* {
    let $docURI := string($treeItem/properties/property[@name = 'uri'])
    return

      {string($treeItem/label)}
      [{linkmgr:makeLinkToDocSource($docURI)}]
      {if ($treeItem/children)
          then

{
             for $child in $treeItem/children/treeItem
                   return linkmgr:treeItemToHtml($child)
             }

          else ()
      }

};

(:~
 : Constructs an HTML representation of the navigation tree of a DITA map.
 :)
declare function linkmgr:getMapNavTree($doc) as node()* {

     {linkmgr:getNavTreeForTopicrefChildren($doc/*)}

};

(: Constructs a navigation tree list item for a sub amp :)
declare function linkmgr:getNavTreeForSubmap($topicref) as node()* {

   let $mapElem := df:resolveTopicRef($topicref)
   return if ($mapElem)
      then linkmgr:getNavTreeForTopicrefChildren($mapElem)
      else ()
};

(: Constructs a navigation tree list item for a topicref :)
declare function linkmgr:getNavTreeForTopicGroup($topicref) as node()* {
  linkmgr:getNavTreeForTopicrefChildren($topicref)
};

declare function linkmgr:getNavTreeForTopicrefChildren($context as element()) as node()* {
  for $child in $context/*[df:class(., 'map/topicref')][not(df:isResourceOnly(.))]
      return
        if (df:isTopicGroup($child))
           then linkmgr:getNavTreeForTopicGroup($child)
           else if (df:isMapRef($child))
                then linkmgr:getNavTreeForSubmap($child)
                else linkmgr:getNavTreeForTopicref($child)
};

(: Constructs a navigation tree list item for a topicref :)
declare function linkmgr:getNavTreeForTopicref($topicref) as node()* {
  let $navTitle := df:getNavtitleForTopicref($topicref)
  let $format := df:getEffectiveAttributeValue($topicref, 'format')
  let $targetResource :=
      if ($format = 'dita')
         then
            try {
             df:resolveTopicRef($topicref)
            } catch * {
             ()
            }
         else ()
  let $resourceRef :=
      if ($topicref/@keyref != '')
        then concat('Keyref [', $topicref/@keyref, ']')
        else concat('URI ref "', $topicref/@href, '"')
  let $childNavTree := linkmgr:getNavTreeForTopicrefChildren($topicref)
  return

      [{name($topicref)}]
      {
        if ($navTitle != '')
           then $navTitle
           else if ($format = 'dita')
                   then '{Resource not resolved}'
                   else concat($format, ' resource')
      }
      {
      (: FIXME: Is the resource can't be resolved, need to resolve the topicref
                to the URI of the ultimate target, if there is one.
       :)

      if (not(df:isTopicHead($topicref)))
           then
            {
            if ($targetResource)
                then linkmgr:makeLinkToDocSource(document-uri(root($targetResource)))
                else $resourceRef
            }]
           else ''}
      {if ($childNavTree)
          then

{
              $childNavTree
            }

          else ()
      }

};

(:~
 : DITA for Small Teams
 :
 : Link management application RESTXQ implementation.
 :
 : Copyright (c) 2015 DITA for Small Teams (dita-for-small-teams.org)
 :
 : See the BaseX RESTXQ documentation for details on how the RESTXQ
 : mechanism works.
 :
 :)
module namespace linkmgr='http://basex.org/modules/linkmgr';

import module namespace bxutil="http://dita-for-small-teams.org/xquery/modules/basex-utils";
import module namespace linkutil="http://dita-for-small-teams.org/xquery/modules/linkmgmt-utils";
import module namespace df="http://dita-for-small-teams.org/xquery/modules/dita-utils";

declare
  %rest:path("/linkmgr/maptreeView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:maptreeView($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $map := doc($docURI)
   let $tree := df:getMapTree($map)
   return

      <title>Map Tree for {df:getTitleText($map/*)}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Map Tree for "{df:getTitleText($map/*)}"

      {linkmgr:reportDocDetails($map)}

       {
        linkmgr:treeToHtml($tree)
       }

};

declare
  %rest:path("/linkmgr/navtreeView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:navtreeView($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $map := doc($docURI)
   let $tree := linkmgr:getMapNavTree($map)
   return

      <title>Nav Tree for {df:getTitleText($map/*)}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Navigation Tree for "{df:getTitleText($map/*)}"

      {linkmgr:reportDocDetails($map)}

       { $tree }

};

(:~
 : Document source view
 :)
declare
  %rest:path("/linkmgr/docview/{$docURI=.+}/src")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewSource($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Source for Document {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Source for Document "{$title}"

      {linkmgr:reportDocDetails($doc)}

        {serialize($doc)}

};

(:~
 : Document dependency view
 :)
declare
  %rest:path("/linkmgr/dependencyView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewDependencies($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Dependencies for Document {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Dependencies for Document "{$title}"

      {linkmgr:reportDocDetails($doc)}

Content references

List of content references goes here

      { if (df:isMap($doc))
           then linkmgr:listMapDependencies($doc)
           else linkmgr:listTopicDependencies($doc)
      }

};

(:~
 : Document where-used view
 :)
declare
  %rest:path("/linkmgr/whereUsedView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewWhereUsed($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Where-Used Report for Document {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Where-Used Report for Document "{$title}"

      {linkmgr:reportDocDetails($doc)}

Users of This Document

List of documents that have some form of pointer to this document.

      { if (df:isMap($doc))
           then linkmgr:listMapWhereUsed($doc)
           else linkmgr:listTopicWhereUsed($doc)
      }

};

declare function linkmgr:listMapWhereUsed($doc as document-node()) as node()* {

Used As a Submap

List of maps that use this map as a submap. Indicates
        whether the use is direct or indirect.

Used as a Peer Map

List of maps that make a peer map reference to this map

Used Via Peer Key Reference

List of documents (maps and topics) that make a peer-map reference to this map.

External-Scope Resources

List of external-scope resources goes here

};

declare function linkmgr:listTopicWhereUsed($doc as document-node()) as node()* {

Used As a Submap

List of maps that use this map as a submap. Indicates
        whether the use is direct or indirect.

Used as a Peer Map

List of maps that make a peer map reference to this map

Used Via Peer Key Reference

List of documents (maps and topics) that make a peer-map reference to this map.

External-Scope Resources

List of external-scope resources goes here

};

declare function linkmgr:listMapDependencies($doc as document-node()) as node()* {

DITA Topics

List of dita topics used from this map

DITA Maps

List of dita topics used from this map

Local-Scope Non-DITA Resources

List of local-scope non-DITA resources goes here

External-Scope Resources

List of external-scope resources goes here

};

declare function linkmgr:listTopicDependencies($doc as document-node()) as node()* {

Image References

List of referenced images goes here

Cross references

List of cross references goes here

Related Links

List of related links goes here

};

(:~
 : Document relationship table view
 :)
declare
  %rest:path("/linkmgr/reltableView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewReltables($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Relationship Tables for Map {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Relationship Tables for Map "{$title}"

      {linkmgr:reportDocDetails($doc)}

Reltables

Relationship tables go here

};

(:~
 : Document relationship table view
 :)
declare
  %rest:path("/linkmgr/keyspaceView/{$docURI=.+}")
  %output:method("xhtml")
  %output:omit-xml-declaration("no")
  %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN")
  %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")
  function linkmgr:docViewKeyspaces($docURI as xs:string)
  as element(Q{http://www.w3.org/1999/xhtml}html)
{
   let $doc := doc($docURI)
   let $title := df:getTitleText($doc/*)
   return

      <title>Key Spaces for Map {$title}</title>
      <link rel="stylesheet" type="text/css" href="/static/style.css"/>

Key Spaces for Map "{$title}"

      {linkmgr:reportDocDetails($doc)}

Key Spaces

Key spaces go here

};

(:~
 : Constructs an HTML report of the details about a document
 :)
declare function linkmgr:reportDocDetails($doc as document-node()) as node()* {
   let $docURI := bxutil:getPathForDoc($doc)
   let $repo as xs:string := bxutil:getGitRepoForDoc($doc)
   let $branch as xs:string := bxutil:getGitBranchForDoc($doc)
   let $isDITA as xs:boolean := df:isDitaDoc($doc)
   return

URI: {linkmgr:makeLinkToDocSource(document-uri($doc))}

Branch: {$repo}/{$branch}

Is DITA: {$isDITA}

};

(:~
 : Takes a generic tree XML structure and generates appropriate HTML
 : markup for it.
 :
 : A tree consists of a sequence of <treeItem> elements, where each tree item
 : has the structure:
 :
 : <treeItem>
 :   label text
 :   <properties>
 :    <prop name="name">value</prop>
 :   </properties>
 :   <children>
 :    <treeItem>
 :   </children>
 : </treeItem>
 :)
declare function linkmgr:treeToHtml($tree as element(mapTree)) as node()* {

{
      for $treeItem in $tree/*
          return linkmgr:treeItemToHtml($treeItem)
    }

};

declare function linkmgr:makeLinkToDocSource($docURI as xs:string) as node()* {
     if ($docURI != '')
       then {bxutil:getPathForDocURI($docURI)}
       else $docURI
};

declare function linkmgr:treeItemToHtml($treeItem as element()) as node()* {
    let $docURI := string($treeItem/properties/property[@name = 'uri'])
    return

      {string($treeItem/label)}
      [linkmgr:makeLinkToDocSource($docURI)]
      {if ($treeItem/children)
          then

{
             for $child in $treeItem/children/treeItem
                   return linkmgr:treeItemToHtml($child)
             }

          else ()
      }

};

(:~
 : Constructs an HTML representation of the navigation tree of a DITA map.
 :)
declare function linkmgr:getMapNavTree($doc) as node()* {

     {linkmgr:getNavTreeForTopicrefChildren($doc/*)}

};

(: Constructs a navigation tree list item for a sub amp :)
declare function linkmgr:getNavTreeForSubmap($topicref) as node()* {

   let $mapElem := df:resolveTopicRef($topicref)
   return if ($mapElem)
      then linkmgr:getNavTreeForTopicrefChildren($mapElem)
      else ()
};

(: Constructs a navigation tree list item for a topicref :)
declare function linkmgr:getNavTreeForTopicGroup($topicref) as node()* {
  linkmgr:getNavTreeForTopicrefChildren($topicref)
};

declare function linkmgr:getNavTreeForTopicrefChildren($context as element()) as node()* {
  for $child in $context/*[df:class(., 'map/topicref')][not(df:isResourceOnly(.))]
      return
        if (df:isTopicGroup($child))
           then linkmgr:getNavTreeForTopicGroup($child)
           else if (df:isMapRef($child))
                then linkmgr:getNavTreeForSubmap($child)
                else linkmgr:getNavTreeForTopicref($child)
};

(: Constructs a navigation tree list item for a topicref :)
declare function linkmgr:getNavTreeForTopicref($topicref) as node()* {
  let $navTitle := df:getNavtitleForTopicref($topicref)
  let $format := df:getEffectiveAttributeValue($topicref, 'format')
  let $targetResource :=
      if ($format = 'dita')
         then
            try {
             df:resolveTopicRef($topicref)
            } catch * {
             ()
            }
         else ()
  let $resourceRef :=
      if ($topicref/@keyref != '')
        then concat('Keyref [', $topicref/@keyref, ']')
        else concat('URI ref "', $topicref/@href, '"')
  let $childNavTree := linkmgr:getNavTreeForTopicrefChildren($topicref)
  return

      [{name($topicref)}]
      {
        if ($navTitle != '')
           then $navTitle
           else if ($format = 'dita')
                   then '{Resource not resolved}'
                   else concat($format, ' resource')
      }
      {
      (: FIXME: Is the resource can't be resolved, need to resolve the topicref
                to the URI of the ultimate target, if there is one.
       :)

      if (not(df:isTopicHead($topicref)))
           then
            {
            if ($targetResource)
                then linkmgr:makeLinkToDocSource(document-uri(root($targetResource)))
                else $resourceRef
            }]
           else ''}
      {if ($childNavTree)
          then

{
              $childNavTree
            }

          else ()
      }

};