Skip to content

Commit

Permalink
Merge pull request #446 from hrennau/feature/documentation-tables-xcore
Browse files Browse the repository at this point in the history
Feature/documentation tables xcore - see PR#438
  • Loading branch information
sgrossberndt authored Jun 19, 2024
2 parents f24060a + cba878b commit 946b9b5
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 36 deletions.
11 changes: 8 additions & 3 deletions docs/generate_tables/xco-domain.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ declare function dm:constructDomains($customDomains as element()?,
: C o m p i l e f i l t e r d o m a i n s
:)
(:~
: Compiles custom domain defintions, type "filter domain".
: Compiles custom domain definitions, type "filter domain".
:)
declare function dm:compileFilterDomains(
$schemaDescriptors as element()*,
Expand All @@ -211,15 +211,20 @@ declare function dm:compileFilterDomains(
dm:filterSchemaDescriptorsByTns(., $schemaDescriptors)
let $tnsMinus :=
$domain/content/exceptTargetNamespace/
dm:filterSchemaDescriptorsByFiles(., $schemaDescriptors)
dm:filterSchemaDescriptorsByTns(., $schemaDescriptors)
let $filesPlus := $domain/content/files/
dm:filterSchemaDescriptorsByFiles(., $schemaDescriptors)
let $filesMinus := $domain/content/exceptFiles/
dm:filterSchemaDescriptorsByFiles(., $schemaDescriptors)
let $selected := ($tnsPlus, $filesPlus)
[not(. = ($tnsMinus, $filesMinus))]
(: Remove repeated selections (2024-05-22, hjr) :)
let $selectedDedup :=
for $xsdd in $selected
group by $filePath := $xsdd/@filePath/lower-case(.)
return $xsdd[1]
let $selectedOrdered :=
dm:sortSchemaDescriptors($selected, $domain)
dm:sortSchemaDescriptors($selectedDedup, $domain)
let $id := 'd'||$pos
let $name := ($domain/@name, $id)[1]
let $summary := $domain/dm:filterDomainSummary(.)
Expand Down
4 changes: 4 additions & 0 deletions docs/generate_tables/xco-edesc-util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ declare function eu:contentTable_elemRow(
let $startChoice := (
array:flatten($startedChoices)/eu:getChoiceSummary(.) => string-join('; ')
)[string()]
let $choiceOcc :=
let $values := $startedChoices?* ! @z:occ => string-join('; ')
return $values ! attribute startChoiceOcc {.}
return
<row typeCategory="{$typeCategory}">{
(: The @startChoice attribute will trigger a text line similar to
"The element contains one of ..." :)
$startChoice ! attribute startChoice {.},
$choiceOcc,
$groupCol,
$branchCol,
<name colspan="{$nameColspan}" rowspan="1">{
Expand Down
4 changes: 3 additions & 1 deletion docs/generate_tables/xco-edesc.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ declare function ed:writeExpandedCompDescsPerDomain(

(: Create schema reports:
: descriptors are grouped by schema and wrapped in schema elements :)
let $schemaMap := map:merge(
$schemas/map:entry(base-uri(.) ! u:normalizeUri(., ()), .))
let $schemaReports :=
for $edesc in $edescs
group by $baseUri := $edesc/base-uri(.) ! u:normalizeUri(., ())
return
<z:schema xml:base="{$baseUri}" filePath="{$baseUri}">{
if ($options?skipAnno) then () else
let $schema := $schemas[base-uri(.) eq $baseUri]
let $schema := $schemaMap($baseUri)
return $schema/xs:annotation[1]/cd:annotationDescriptor(.),
<z:components count="{count($edesc)}">{$edesc}</z:components>
}</z:schema>
Expand Down
95 changes: 64 additions & 31 deletions docs/generate_tables/xco-html.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ declare function hl:contabReport($report as element()?,
};

(:~
: Transforms an edesc report or report domain into a contab report.
: Creates a section of a contab report, describing a domain.
:
: If no domains have been defined, the function creates the complete
: report, otherwise the part corresponding to a single domain.
Expand All @@ -110,25 +110,25 @@ declare function hl:contabReport_domain(
let $anno := $schema/z:annotation/z:documentation/string()
let $headline := ($anno, $schemaFileName)[1]
let $stypes := $schema/eu:getEdescReportSimpleTypes(.)
let $stypesTable := eu:stypesTable($stypes, $domain, $options)[$stypes]
let $stypesTable := eu:stypesTable($stypes, $domain, $options)[$stypes]

(: Deduplicate and sort local types :)
let $localTypes :=
for $ltype in $schema/z:components/*//z:complexType[@z:typeID]
group by $typeId := $ltype/@z:typeID
order by $typeId ! replace(., '.*typedef-(.*)', '$1') ! xs:decimal(.)
return $ltype[1]! u:copyNode(.)
let $tables :=
for $comp at $cnr in (
$schema/z:components/*,
$schema/z:components/*//z:complexType[@z:typeID] ! u:copyNode(.)
$schema/z:components/*
[self::z:complexType, self::z:group, self::z:element],
$localTypes
)
let $compNr :=
let $shift := if ($stypes) then 1 else 0
return $cnr + $shift
return
typeswitch($comp)
case element(z:complexType) |
element(z:group) |
element(z:element) return
hl:contabReport_complexComp($comp, $compNr, $schemaNr, $domain, $options)
case element(z:simpleType) return ()
case element(z:attributeGroup) return ()
case element(z:attribute) return ()
default return error('Unexpected component, elem name: '||name($comp))
hl:contabReport_complexComp($comp, $compNr, $schemaNr, $domain, $options)
return
<div class="sect1" id="schema_{$schemaName}">{
<h2>{$schemaNr}. {$headline}</h2>,
Expand Down Expand Up @@ -156,7 +156,7 @@ declare function hl:contabReport_domain(
let $_WRITE :=
let $reportPath := dm:getReportPath('contab', $domain, $options)
where ($reportPath)
return u:writeXmlDoc($reportPath, $htmlReport)
return u:writeXhtmlDoc($reportPath, $htmlReport)
return $htmlReport
};

Expand Down Expand Up @@ -249,11 +249,11 @@ declare function hl:contabReport_head(
<script type="text/javascript"><![CDATA[
document.addEventListener('DOMContentLoaded', function() {
var headers = ['h2', 'h3', 'h4', 'h5', 'h6'];
for (var i = 0; i &lt; headers.length; i++) {
for (var i = 0; i < headers.length; i++) {
var headerElements = document.getElementsByTagName(headers[i]);
for (var j = 0; j &lt; headerElements.length; j++) {
for (var j = 0; j < headerElements.length; j++) {
var header = headerElements[j];
header.innerHTML += '&lt;a class="header-link" href="#' + header.parentNode.id + '"&gt;&lt;span class="link-icon"&gt;&lt;/span&gt;&lt;/a&gt;';
header.innerHTML += '<a class="header-link" href="#' + header.parentNode.id + '"><span class="link-icon"></span></a>';
}
}
});
Expand Down Expand Up @@ -587,11 +587,13 @@ optional, single, part of a choice
'Inherited content is followed by ', <b>own content</b>, ':')

let $startChoiceItems := $row/@startChoice/tokenize(., ';\s*')
let $startChoiceOccItems := $row/@startChoiceOcc/tokenize(., ';\s*')
(: let $_DEBUG := $row[@startChoice] ! trace(.) :)
return (
hu:tableTextLine($startOwnContentMsg, 'announceBase', ())[$startOwnContent]
,
if (empty($startChoiceItems)) then () else
for $startChoiceItem in $startChoiceItems
for $startChoiceItem at $choiceNr in $startChoiceItems
let $items := tokenize($startChoiceItem, ',\s*')
let $contextbranch := $items[starts-with(., 'contextbranch')] ! substring-after(., '=')
let $elems := $items[starts-with(., 'elems')] ! substring-after(., '=')
Expand All @@ -604,9 +606,19 @@ optional, single, part of a choice
$elems ! ('elements ('||$elems||')'),
$seqs ! ('element sequences ('||$seqs||')')
), ' or ')
let $oneOrNoneOrOne :=
let $occs := $startChoiceOccItems[$choiceNr]
let $minOcc := substring-before($occs, ':')
let $maxOcc := substring-after($occs, ':')
return
if ($minOcc eq '0') then
let $alter := if ($maxOcc eq '*') then 'more' else 'one'
return 'none or '||$alter
else if ($maxOcc eq '*') then 'one or more'
else 'one'
return
hu:tableTextLine(
($startText, 'element contains ', <em>one</em>,
($startText, 'element contains ', <em>{$oneOrNoneOrOne}</em>,
' of the following '||$alternatives))
,
<tr>{
Expand Down Expand Up @@ -650,9 +662,15 @@ optional, single, part of a choice
<p>{
hu:classP(),
if ($isMandatory) then
<code><strong title="{$occTitle}">{$occValue}</strong></code>
<strong title="{$occTitle}">{$occValue}</strong>
else
<span title="{$occTitle}">{$occValue}</span>
(: Alternative with <code> - not used
if ($isMandatory) then
<code><strong title="{$occTitle}">{$occValue}</strong></code>
else
<code><span title="{$occTitle}">{$occValue}</span></code>
:)
}</p>
}</td>,
$row/type/
Expand Down Expand Up @@ -773,7 +791,7 @@ declare function hl:contabReportIndex(
}</html>
! u:prettyNode(.)

let $_WRITE := u:writeXmlDoc($filePath, $htmlReport)
let $_WRITE := u:writeXhtmlDoc($filePath, $htmlReport)

return $htmlReport
};
Expand All @@ -795,7 +813,7 @@ declare function hl:contabReportIndex_toc(
let $filePath := dm:getReportPath('contab', $domain, $options)
let $relPath := fu:getRelPath($dirPath, $filePath)
let $fileName := $relPath ! file:name(.)
let $title := $domain/processing/title/string()
let $title := $domain/processing/(titleToplevel, title, $fileName)[1] ! string()
let $enumPath :=
dm:getReportPartPath('contab', 'enum-dict', $domain, $options)[file:exists(.)]
let $enumRelPath := $enumPath ! fu:getRelPath($dirPath, .)
Expand Down Expand Up @@ -833,7 +851,7 @@ declare function hl:contabReportIndex_toc(
<h4>{$title}</h4>
<p class="tocsubtitle">{$subtitle}</p>
</div>
<ul class="sectlevel1">{
<ul class="sectlevel1" id="ulstartpage">{
$linkTree
}</ul>
</div>
Expand All @@ -853,7 +871,16 @@ declare function hl:contabReportIndex_tocTree(
$domainDict as map(xs:string, item()*),
$options as map(xs:string, item()*)?)
as element(li)* {
hl:contabReportIndex_tocTreeREC($ftree, $domainDict, $options)
(: Determine where file entries should have a prefix indicating
the level of indentation - only if different labels occur. :)
let $options_indentationLabel :=
if (empty($ftree//fi[count(ancestor::fo) gt 1])) then 'no'
else 'yes'
let $optionsTocTree :=
map:put($options, 'withIndentationLabel',
$options_indentationLabel)
return
hl:contabReportIndex_tocTreeREC($ftree, $domainDict, $optionsTocTree)
};

declare function hl:contabReportIndex_tocTreeREC(
Expand All @@ -864,11 +891,15 @@ declare function hl:contabReportIndex_tocTreeREC(
typeswitch($n)
case element(fo) return
let $level := count($n/ancestor::fo)
let $prefix := (for $i in 1 to $level return '>> ') => string-join('')
let $prefix :=
if ($options?withIndentationLabel eq 'no') then () else
(for $i in 1 to $level return '>> ') => string-join('')
let $name := $n/@name/string()
return (
if (not($name)) then () else
<li>{
<span class="monospace">{$prefix}</span>,
<span class="darkbrown">{$n/@name/string()}</span>
$prefix ! <span class="monospace">{.}</span>,
<span class="darkbrown">{$name}</span>
}</li>,
$n/* ! hl:contabReportIndex_tocTreeREC(., $domainDict, $options)
)
Expand All @@ -879,16 +910,18 @@ declare function hl:contabReportIndex_tocTreeREC(

let $path := $n/ancestor-or-self::*/@name => string-join('/')
let $level := count($n/ancestor::fo)
let $prefix := (for $i in 1 to $level return '. ') => string-join('')
let $prefix :=
if ($options?withIndentationLabel eq 'no') then () else
(for $i in 1 to $level return '. ') => string-join('')
let $dinfo := $domainDict($path)
let $href := $dinfo?relPath
let $title := $dinfo?fileName||
let $title := $dinfo?title||
($dinfo?countEnumTypes[string()] ! (' ('||.||')'))
let $titleClass := attribute class {'enum-dict'}
[contains($href, 'enum-dict')]
return
<li>{
<span class="monospace">{$prefix}</span>,
$prefix ! <span class="monospace">{.}</span>,
<a shape="rect" href="{$href}">{$titleClass, $title}</a>
}</li>
default return ()
Expand Down Expand Up @@ -952,7 +985,7 @@ declare function hl:enumDict_domain(
let $_WRITE :=
let $reportPath := dm:getReportPartPath('contab', 'enum-dict', $domain, $options)
where ($reportPath)
return u:writeXmlDoc($reportPath, $htmlReport)
return u:writeXhtmlDoc($reportPath, $htmlReport)

return $htmlReport
};
Expand Down
2 changes: 1 addition & 1 deletion docs/generate_tables/xco-reporter.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ declare function rp:contabReport(
let $_WDEBUG := $xmlReport ! dg:WRITE_FILE(., 'EDESC-REPORT.XML', 'edesc-report', 'yes', $options)
let $_LOG := trace('Write contab reports')
let $htmlReport := hl:htmlReport('contab', $xmlReport, $xmlReportDir, $options) ! u:prettyNode(.)
let $_LOG := trace('Writing of contab reports fininshed')
let $_LOG := trace('Writing of contab reports finished')
return ()
};

Expand Down
33 changes: 33 additions & 0 deletions docs/generate_tables/xco-util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,36 @@ declare function u:writeXmlDoc($path as xs:string,
u:writeXmlDoc($path, $doc, ())
};

(:~
: Writes an XHTML document to the file system. If the folder does not
: yet exist, it is created now.
:
: If no serialization parameters are specified, the output document
: is indented.
:
: @param path the file system path of the output file
: @param doc the document to be written (document or element node)
: @serParams optional serialization parameters
: @return the empty sequence
:)
declare function u:writeXhtmlDoc($path as xs:string,
$doc as node(),
$serParams as map(xs:string, item()*)?)
as empty-sequence() {
let $dir := $path ! replace(., '/[^/]*$', '')
let $_CRDIR := if (file:exists($dir)) then () else file:create-dir($dir)
let $spar := if (exists($serParams)) then $serParams else
map{'method': 'xhtml',
'cdata-section-elements': 'script',
'indent': 'yes',
'html-version': '5.0'
}
return
file:write($path, $doc, $spar)
};

declare function u:writeXhtmlDoc($path as xs:string,
$doc as node())
as empty-sequence() {
u:writeXhtmlDoc($path, $doc, ())
};

0 comments on commit 946b9b5

Please sign in to comment.