Skip to content

Instantly share code, notes, and snippets.

@eerohele
Created November 13, 2015 22:58
Show Gist options
  • Save eerohele/10baaced6a6a5a245044 to your computer and use it in GitHub Desktop.
Save eerohele/10baaced6a6a5a245044 to your computer and use it in GitHub Desktop.
Get a list of all topics that belong to a given DITA map. Descends into submaps.
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
declare variable $CLASS_MAP_TOPICREF := " map/topicref ";
declare variable $SCOPE_LOCAL := "local";
declare variable $FORMAT_DITA := "dita";
declare variable $FORMAT_DITAMAP := "ditamap";
declare function local:is-local-topicref($el as element()) as xs:boolean {
contains($el/@class, $CLASS_MAP_TOPICREF)
and (empty($el/@format)
or $el/@format eq $FORMAT_DITA or $el/@format eq $FORMAT_DITAMAP)
and (empty($el/@scope)
or $el/@scope eq $SCOPE_LOCAL)
};
declare function local:get-local-topicrefs($doc as document-node()) as xs:anyURI* {
base-uri($doc),
for $topicref in $doc//*[local:is-local-topicref(.)][normalize-space(@href)]
let $uri := resolve-uri($topicref/@href, base-uri($topicref))
return if (lower-case($topicref/@format) eq $FORMAT_DITAMAP)
then local:get-local-topicrefs(doc($uri))
else $uri
};
let $doc := .
return string-join(distinct-values(local:get-local-topicrefs($doc)), '
')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment