44 xmlns : xsl =" http://www.w3.org/1999/XSL/Transform"
55 exclude-result-prefixes =" xs" >
66
7- <xsl : output encoding =" UTF-8" method =" text" indent =" false" />
8-
7+ <xsl : output method =" json" encoding =" UTF-8" indent =" yes" />
8+
9+ <xsl : mode name =" termentry" on-no-match =" shallow-skip" />
10+ <xsl : mode name =" termref" on-no-match =" shallow-skip" />
11+
912 <xsl : param name =" dita.temp.dir.url" as =" xs:anyURI" />
1013 <xsl : param name =" output.dir.url" as =" xs:anyURI" />
1114 <xsl : param name =" source.language" as =" xs:string" />
1215
13- <xsl : mode name =" termref" on-no-match =" shallow-skip" />
14- <xsl : mode name =" termentry" on-no-match =" shallow-skip" />
15- <xsl : mode name =" preferred-term" on-no-match =" shallow-skip" />
16- <xsl : mode name =" admitted-term" on-no-match =" shallow-skip" />
17-
1816 <xsl : variable name =" termentry-topics" select =" collection($dita.temp.dir.url || '?select=*.dita;recurse=yes')" />
19- <xsl : variable name =" languages" >
17+
18+ <xsl : variable name =" languages" as =" xs:string*" >
2019 <xsl : for-each select =" distinct-values($termentry-topics//@language)" >
21- <xsl : value-of select =" distinct-values(.) || ', '" />
20+ <xsl : variable name =" lang" select =" normalize-space(.)" />
21+ <xsl : if test =" $lang != $source.language and contains($lang, '-')" >
22+ <xsl : sequence select =" $lang" />
23+ </xsl : if >
2224 </xsl : for-each >
2325 </xsl : variable >
2426
25- <!-- Match on the input terminology DITA Map. -->
26-
27- <!-- {
28- "Anlage": "system",
29- "Techniker": "technician",
30- "Dokumentation": "documentation",
31- "Anhang": "appendix",
32- "Steuerung": "control unit",
33- "Bediener": "operator"
34- }-->
3527 <xsl : template match =" /" >
3628 <xsl : variable name =" root" select =" ." as =" node()" />
37- <xsl : for-each select =" tokenize($languages, ',')" >
38- <xsl : if test =" contains(., '-')" >
39- <xsl : variable name =" language" select =" normalize-space(.)" />
40- <xsl : result-document href =" {$output.dir.url || '/terminology_' || $language || '.json'}" >
41- <xsl : text >{ </xsl : text >
29+ <xsl : for-each select =" $languages" >
30+ <xsl : variable name =" target.language" select =" ." />
31+ <xsl : result-document href =" {$output.dir.url || '/terminology_' || $target.language || '.json'}" method =" json" >
32+ <xsl : map >
4233 <xsl : apply-templates select =" $root" mode =" termref" >
43- <xsl : with-param name =" language" select =" $language" />
34+ <xsl : with-param name =" target. language" select =" $target. language" />
4435 </xsl : apply-templates >
45- <xsl : text >}</xsl : text >
46- </xsl : result-document >
47- </xsl : if >
36+ </xsl : map >
37+ </xsl : result-document >
4838 </xsl : for-each >
4939 </xsl : template >
50-
51- <!-- Fall through -->
52- <xsl : template match =" topicref" mode =" termref" />
53- <xsl : template match =" semanticnetref" mode =" termref" />
54- <xsl : template match =" termstatsref" mode =" termref" />
5540
5641 <xsl : template match =" termref[@href][@keys]" mode =" termref" >
57- <xsl : param name =" language" as =" xs:string" />
58- <xsl : variable name =" key" select =" lower-case(@keys)" as =" xs:string" />
59- <xsl : variable name =" filename" select =" @href" as =" xs:string" />
60- <xsl : variable name =" t" select =" xs:anyURI($dita.temp.dir.url || $filename)" as =" xs:anyURI" />
42+ <xsl : param name =" target.language" as =" xs:string" />
43+ <xsl : variable name =" filename" select =" @href" />
44+ <xsl : variable name =" t" select =" xs:anyURI($dita.temp.dir.url || $filename)" />
6145 <xsl : apply-templates select =" document($t)" mode =" termentry" >
62- <xsl : with-param name =" language" select =" $language" />
46+ <xsl : with-param name =" target. language" select =" $target. language" />
6347 </xsl : apply-templates >
6448 </xsl : template >
6549
66- <xsl : template match =" termentry" mode =" termentry" expand-text =" yes" >
67- <xsl : param name =" language" as =" xs:string" />
68- <xsl : variable name =" root" as =" node()" select =" ." />
50+ <xsl : template match =" termentry" mode =" termentry" >
51+ <xsl : param name =" target.language" as =" xs:string" />
6952 <xsl : variable name =" term.source" select ="
70- normalize-space(
71- $root//*
72- [contains(@class, ' termentry/termNotation ')]
73- [@usage = 'preferred']
74- [@language = $source.language][1]
75- )
76- " />
53+ normalize-space(.//*[contains(@class, ' termentry/termNotation ')]
54+ [@usage='preferred']
55+ [@language=$source.language][1]/*[contains(@class, ' termentry/termVariant ')][1]/text())" />
7756 <xsl : variable name =" term.target" select ="
78- normalize-space(
79- $root//*
80- [contains(@class, ' termentry/termNotation ')]
81- [@usage = 'preferred']
82- [@language = $language][1]
83- )
84- " />
85- <xsl : if test =" $term.source != '' and $term.target !=''" >
86- <xsl : sequence select =" '" ' || $term.source || '" : " ' || $term.target || '" , '" />
57+ normalize-space(.//*[contains(@class, ' termentry/termNotation ')]
58+ [@usage='preferred']
59+ [@language=$target.language][1]/*[contains(@class, ' termentry/termVariant ')][1]/text())" />
60+ <xsl : if test =" $term.source != '' and $term.target != ''" >
61+ <xsl : map-entry key =" $term.source" select =" $term.target" />
8762 </xsl : if >
8863 </xsl : template >
8964
90- </xsl : stylesheet >
65+ </xsl : stylesheet >
0 commit comments