Skip to content

Commit b7e8084

Browse files
committed
Issue #2 Integrated basic catalog resolution code. Current code runs without failure when no catalog URL is specified
1 parent 8b627bc commit b7e8084

File tree

10 files changed

+165
-4
lines changed

10 files changed

+165
-4
lines changed

build.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
<arg line="generateModules=${doGenerateModules}"/>
272272
<arg line="generateStandardModules=${doGenerateStandardModules}"/>
273273
<arg line="generateCatalogs=${doGenerateCatalogs}"/>
274+
<arg line="catalogUrl=&quot;${catalogPathUrl}&quot;"/>
274275
</java>
275276

276277
</target>
@@ -294,6 +295,7 @@
294295
<arg line="rootDir=${rngsrcUrl}"/>
295296
<arg line="generateModules=${doGenerateModules}"/>
296297
<arg line="generateStandardModules=${doGenerateStandardModules}"/>
298+
<arg line="catalogUrl=&quot;${catalogPathUrl}&quot;"/>
297299
</java>
298300
</target>
299301

@@ -317,6 +319,7 @@
317319
<arg line="rootDir=${rngsrcUrl}"/>
318320
<arg line="generateModules=${doGenerateModules}"/>
319321
<arg line="generateStandardModules=${doGenerateStandardModules}"/>
322+
<arg line="catalogUrl=&quot;${catalogPathUrl}&quot;"/>
320323
</java>
321324
</target>
322325

@@ -336,6 +339,7 @@
336339
<arg line="ditaVersion=${ditaver}"/>
337340
<arg line="outdir=&quot;${verSpecificOutDir}&quot;"/>
338341
<arg line="catalogType=${catalogType}"/>
342+
<arg line="catalogUrl=&quot;${catalogPathUrl}&quot;"/>
339343
</java>
340344
</target>
341345

test/specializations/test/myTopic/mytopic-test01-dtd.dita

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE mytopic SYSTEM "../../org.example/1.3/dtd/mytopic/dtd/mytopic.dtd">
2+
<!DOCTYPE mytopic SYSTEM "file:/Users/ekimber/workspace-oasis/dita-rng-converter/build/1.3/dtd/myTopic/dtd/myTopic.dtd">
33
<mytopic id="topic_z55_x5x_fw" >
44
<title>This is a MyTopic topic</title>
55
<body>

xsl/lib/catalog_util.xsl

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
5+
xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog"
6+
xmlns:catutil="http://local/catalog-utility"
7+
exclude-result-prefixes="xs xd catutil"
8+
version="2.0">
9+
10+
<!-- ===========================================================
11+
Resolve URIs through OASIS Open entity resolution catalogs
12+
13+
This is the code as provided by Toshihiko Makita with some
14+
small changes made, mostly to names and comments. No
15+
functional change to the templates or functions.
16+
17+
FIXME: Needs the following improvements:
18+
19+
- Use XSLT 3 maps
20+
- Handle multiple catalog files
21+
- Generalize URI resolution
22+
=========================================================== -->
23+
<xsl:variable name="catalogTree" as="document-node()">
24+
<xsl:document>
25+
<xsl:call-template name="expandCatalogFile"/>
26+
</xsl:document>
27+
</xsl:variable>
28+
29+
<xd:doc>
30+
<xd:desc>Expand catalog file into temporary tree</xd:desc>
31+
</xd:doc>
32+
<xsl:template name="expandCatalogFile">
33+
<catalog>
34+
<xsl:apply-templates select="document($catalogUrl)" mode="MODE_EXPAND_CATALOG">
35+
<xsl:with-param name="prmCatalogDir" tunnel="yes" select="$catalogUrl"/>
36+
</xsl:apply-templates>
37+
</catalog>
38+
</xsl:template>
39+
40+
<xsl:template match="/" mode="MODE_EXPAND_CATALOG">
41+
<xsl:apply-templates select="*" mode="#current"/>
42+
</xsl:template>
43+
44+
<xsl:template match="cat:*" mode="MODE_EXPAND_CATALOG"/>
45+
46+
<xsl:template match="cat:catalog" mode="MODE_EXPAND_CATALOG">
47+
<xsl:apply-templates select="*" mode="#current"/>
48+
</xsl:template>
49+
50+
<xsl:template match="cat:nextCatalog" mode="MODE_EXPAND_CATALOG">
51+
<xsl:param name="prmCatalogDir" tunnel="yes" as="xs:string"/>
52+
<xsl:variable name="nextCatalog" as="xs:string" select="string(@catalog)"/>
53+
<xsl:variable name="fullNextCatalogDir" as="xs:string" select="string(resolve-uri($nextCatalog,$prmCatalogDir))"/>
54+
<xsl:apply-templates select="document($nextCatalog,.)" mode="#current">
55+
<xsl:with-param name="prmCatalogDir" tunnel="yes" select="$fullNextCatalogDir"/>
56+
</xsl:apply-templates>
57+
</xsl:template>
58+
59+
<xsl:template match="cat:group" mode="MODE_EXPAND_CATALOG">
60+
<xsl:apply-templates select="*" mode="#current"/>
61+
</xsl:template>
62+
63+
<xsl:template match="cat:uri" mode="MODE_EXPAND_CATALOG">
64+
<xsl:param name="prmCatalogDir" tunnel="yes" as="xs:string"/>
65+
66+
<xsl:variable name="name" select="string(@name)"/>
67+
<xsl:variable name="uri" select="string(@uri)"/>
68+
<xsl:variable name="fileUri" select="string(resolve-uri($uri, $prmCatalogDir))"/>
69+
<uri id="{$name}" uri="{$fileUri}"/>
70+
</xsl:template>
71+
72+
<xd:doc>
73+
<xd:desc>Resolve a URI to a URI through the configured catalogs</xd:desc>
74+
<xd:param>input-uri: URI to be resolved</xd:param>
75+
<xd:return>File URI. If URI is not mapped, returns input URI.</xd:return>
76+
</xd:doc>
77+
<xsl:function name="catutil:resolve-uri" as="xs:string">
78+
<xsl:param name="input-uri" as="xs:string"/>
79+
80+
<xsl:variable name="resultUri" as="xs:string?"
81+
select="string(($catalogTree/catalog/uri[string(@id) eq $input-uri]/@uri)[1])"
82+
/>
83+
<xsl:choose>
84+
<xsl:when test="exists($resultUri) and not($resultUri eq '')">
85+
<xsl:if test="$debug">
86+
<xsl:message>+ [DEBUG] catutil:resolve-uri(): URI "<xsl:value-of select="$input-uri"/>" is mapped to "<xsl:value-of select="$resultUri"/>"</xsl:message>
87+
</xsl:if>
88+
<xsl:sequence select="$resultUri"/>
89+
</xsl:when>
90+
<xsl:otherwise>
91+
<xsl:message>+ [ERROR] catutil:resolve-uri(): URI "<xsl:value-of select="$input-uri"/>" is not defined in catalog file.</xsl:message>
92+
<xsl:sequence select="$input-uri"/>
93+
</xsl:otherwise>
94+
</xsl:choose>
95+
</xsl:function>
96+
97+
</xsl:stylesheet>

xsl/lib/relpath_util.xsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@
378378
component of the path.
379379
-->
380380
<xsl:param name="sourcePath" as="xs:string"/>
381-
<xsl:value-of select="tokenize($sourcePath, '/')[last()]"/>
381+
<xsl:variable name="result"
382+
select="tokenize($sourcePath, '/')[last()]"
383+
/>
384+
<xsl:sequence select="$result"/>
382385
</xsl:function>
383386

384387
<xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">

xsl/lib/rng2functions.xsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
/>
259259
<xsl:sequence select="$entFilename"/>
260260
</xsl:function>
261-
261+
262262
<xsl:function name="rngfunc:getGrammarUri" as="xs:string">
263263
<xsl:param name="rngGrammar" as="element(rng:grammar)"/>
264264
<xsl:variable name="result" select="if (document-uri(root($rngGrammar)))
@@ -440,9 +440,16 @@
440440

441441
<xsl:function name="rngfunc:isModuleDoc" as="xs:boolean">
442442
<xsl:param name="doc" as="document-node()"/>
443+
<xsl:variable name="base-uri"
444+
as="xs:string"
445+
select="string(document-uri($doc))"
446+
/>
443447
<xsl:variable name="filename" as="xs:string"
444-
select="relpath:getName(string(document-uri($doc)))"
448+
select="relpath:getName($base-uri)"
445449
/>
450+
<!-- FIXME: Need to use the module metadata, not the filename.
451+
See issue #12
452+
-->
446453
<xsl:variable name="result" as="xs:boolean"
447454
select="ends-with($filename, 'Mod.rng')
448455
"

xsl/lib/rng2removeDivs.xsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<xsl:copy>
3636
<xsl:if test="$origURI">
3737
<!--<xsl:message> + [DEBUG] removeDivs: Constructing @origURI attribute</xsl:message>-->
38+
<!--xsl:attribute name="origURI" select="$origURI"/-->
3839
<xsl:attribute name="origURI" select="$origURI"/>
3940
</xsl:if>
4041
<xsl:apply-templates select="@*,node()" mode="#current"/>

xsl/rng2catalogs/rng2catalogs.xsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
============================================================== -->
3636

3737
<xsl:include href="../lib/relpath_util.xsl" />
38+
<xsl:include href="../lib/catalog_util.xsl" />
3839
<xsl:include href="../lib/rng2functions.xsl"/>
3940
<xsl:include href="../lib/rng2gatherModules.xsl"/>
4041
<xsl:include href="../lib/rng2generateCatalogs.xsl"/>
@@ -69,6 +70,18 @@
6970
7071
-->
7172

73+
<xd:doc>
74+
<xd:param>$catalogUrl: File URL of [DITA-OT]/catalog-dita.xml</xd:param>
75+
</xd:doc>
76+
77+
<!-- FIXME: This is used by the catalog utility to resolve URIs through a catalog.
78+
79+
This needs to be replaced with a list of catalogs
80+
and then used to construct a global map representing
81+
the resolved catalogs to be used for URI lookup.
82+
-->
83+
<xsl:param name="catalogUrl" as="xs:string?" select="()"/>
84+
7285
<xsl:output omit-xml-declaration="yes"/>
7386

7487
<xsl:template name="processDir">

xsl/rng2ditadtd/rng2ditadtd.xsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</xd:doc>
4949

5050
<xsl:include href="../lib/relpath_util.xsl" />
51+
<xsl:include href="../lib/catalog_util.xsl" />
5152
<xsl:include href="../lib/rng2functions.xsl"/>
5253
<xsl:include href="../lib/rng2gatherModules.xsl"/>
5354
<xsl:include href="../lib/rng2removeDivs.xsl"/>
@@ -112,6 +113,17 @@
112113
/>
113114

114115

116+
<!-- FIXME: This is used by the catalog utility to resolve URIs through a catalog.
117+
118+
This needs to be replaced with a list of catalogs
119+
and then used to construct a global map representing
120+
the resolved catalogs to be used for URI lookup.
121+
-->
122+
<xd:doc>
123+
<xd:param>$catalogUrl: File URL of [DITA-OT]/catalog-dita.xml</xd:param>
124+
</xd:doc>
125+
<xsl:param name="catalogUrl" as="xs:string?" select="()"/>
126+
115127
<!-- NOTE: The primary output of this transform is an XML
116128
manifest file that lists all input files and their
117129
corresponding outputs.

xsl/rng2ditarnc/rng2ditarnc.xsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
</xd:doc>
3232

3333
<xsl:include href="../lib/relpath_util.xsl" />
34+
<xsl:include href="../lib/catalog_util.xsl" />
3435
<xsl:include href="../lib/rng2functions.xsl"/>
3536
<xsl:include href="../lib/rng2gatherModules.xsl"/>
3637
<xsl:include href="../lib/rng2generateCatalogs.xsl"/>
@@ -80,6 +81,17 @@
8081
select="matches($useURNsInShell, '(yes|true|1|no)', 'i')"
8182
/>
8283

84+
<!-- FIXME: This is used by the catalog utility to resolve URIs through a catalog.
85+
86+
This needs to be replaced with a list of catalogs
87+
and then used to construct a global map representing
88+
the resolved catalogs to be used for URI lookup.
89+
-->
90+
<xd:doc>
91+
<xd:param>$catalogUrl: File URL of [DITA-OT]/catalog-dita.xml</xd:param>
92+
</xd:doc>
93+
<xsl:param name="catalogUrl" as="xs:string?" select="()"/>
94+
8395
<!-- NOTE: The primary output of this transform is an XML
8496
manifest file that lists all input files and their
8597
corresponding outputs.

xsl/rng2ditaxsd/rng2ditaxsd.xsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
version="2.0">
1515

1616
<xsl:include href="../lib/relpath_util.xsl" />
17+
<xsl:include href="../lib/catalog_util.xsl" />
1718
<xsl:include href="../lib/rng2functions.xsl"/>
1819
<xsl:include href="../lib/rng2gatherModules.xsl"/>
1920
<xsl:include href="../lib/rng2generateCatalogs.xsl"/>
@@ -97,6 +98,17 @@
9798
select="matches($useURNsInShell, '(yes|true|1|no)', 'i')"
9899
/>
99100

101+
<!-- FIXME: This is used by the catalog utility to resolve URIs through a catalog.
102+
103+
This needs to be replaced with a list of catalogs
104+
and then used to construct a global map representing
105+
the resolved catalogs to be used for URI lookup.
106+
-->
107+
<xd:doc>
108+
<xd:param>$catalogUrl: File URL of [DITA-OT]/catalog-dita.xml</xd:param>
109+
</xd:doc>
110+
<xsl:param name="catalogUrl" as="xs:string?" select="()"/>
111+
100112
<!-- NOTE: The primary output of this transform is an XML
101113
manifest file that lists all input files and their
102114
corresponding outputs.

0 commit comments

Comments
 (0)