I have one topic and two ditamaps. I want to override variable in nested ditamap. Is it possible?
root.ditamap
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN"
"map.dtd">
<map>
<title>Root</title>
<keydef keys="testvar">
<topicmeta>
<linktext>testvalue</linktext>
</topicmeta>
</keydef>
<topicref href="test.dita"/>
<mapref href="test.ditamap"/>
</map>
test.ditamap
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN"
"map.dtd">
<map>
<title>Testmap</title>
<keydef keys="testvar">
<topicmeta>
<linktext>othervalue</linktext>
</topicmeta>
</keydef>
<topicref href="test.dita"/>
</map>
test.dita
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN"
"topic.dtd">
<topic id="test">
<title>Test header</title>
<body>
<p>var: <keyword keyref="testvar"/></p>
</body>
</topic>
Then I run command:
dita -i root.ditamap -f html5
The result is two links to the same file test.html
Root
Test header
Test header
test.html contents
<!DOCTYPE html
SYSTEM "about:legacy-compat">
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2020"><meta name="DC.rights.owner" content="(C)$
<h1 class="title topictitle1" id="ariaid-title1">Test header</h1>
<div class="body">
<p class="p">var: <span class="keyword">test</span></p>
</div>
</article></main></body></html>
But I expect two files with different variable value.
By default according to the DITA standard the key is set to the first value to which it's initialized and used in the entire set of DITA resources, so defining keys does not work like in programming languages where you can re-define the same variable name in a local context. But in the DITA 1.3 standard a concept called key scoping was added:
which means that if inside the "test.ditamap" you set the "keyscope" attribute on the root map element to some value (the value does not matter much) this means that the key will have that different value inside that key scope. Other examples for using key scopes: