Re: keys and scoped keys #conref

If you have:


+ keys=”key1” {blue}

++ keyscope=”scope1”

+++ keys=”key1” {red}


Then the resolved value of a reference to key “key1” will be “blue” in all contexts because the highest declaration wins.


That is keys are not like normal variables in programming languages, where the nearest declaration wins. This is so that the owner of the root map always has ultimate control over the definitions of all keys.


However, with the above you can refer to key “scope1.key1” which will resolve to the value “red”. But that’s probably not useful for your case.


So as you determined, if you have two peer scopes and you want the same key name to resolve to different values in those two scopes then the keys need to be defined in the scopes, not in an ancestor scope.


Normally you would do this by having a separate map that defines the keys and then include that map into both scopes. This is consistent with the general practice of putting key definitions into submaps to make them easier to manage.


So you could have something like:


+ root map

++ keyscope=”scope1”

+++ keys=”key1” {red}

+++ Reference to keydef map “colors.ditamap”

++ keyscope=”scope2”

+++ Reference to keydef map “colors.ditamap”


Where colors.ditamap is:


+ keys=”key1” {blue}

+ keys=”key2” {red}


With this structure, “key1” resolves to “red” in the context of scope1 and “blue” in the context of scope2. The definition of key “key1” in scope1 overrides the definition of key1 in colors.ditamap because it comes before the reference to colors.ditamap.






Eliot Kimber




From: DITA Users on behalf of DITA Users
Reply-To: DITA Users
Date: Wednesday, September 5, 2018 at 8:36 AM
To: DITA Users
Subject: [dita-users] keys and scoped keys



Hi all,


I’m trying to figure out a use case for scoped keys. After reading this very helpfull article ( I’m wondering if anything has changed for OT 3.x. I’m now using OT 2.5.x.


This is how I would have expecetd it to be implemented - and what I actually need:


In my main project (ditamap) I have defined several keys. Let’s say Key1 defines 'Blue' and Key2 defines ’Square'. 

So all te topics and submaps in my project will resolve keyref to Key1 as 'Blue' and keyref to Key2 as 'Square'.

Now, in one of my submaps I need to refer to a Red Square. I set the keyscope of that map to 'mymapscope'. I define a key named 'Key1’ with value 'Red'. And expect the topics in that map to resolve keyref to Key1 to 'Red', so they display 'Red  Square'. 

But, unfortunately, that’s not the case. The still show 'Blue Square'.


From the above article, I learned that even with key scopes, the parent definition wins over a nested one. For my use case, that would implie that I have to remove the keydefs from my main map, set a keyscope for each and every submap, use the same definitions everywhere, except for one, just to be able to make use of the keyscope features. That adds a lot of overhead and managing keydefs.


So, am I right to conclude that a nested keydef, even within it’s own keyscope, does NOT override a parent keydef? Did this change in OT 3.x - or can anyone point me to an elegant solution for this without the need to repeat the same keydefs for every parrallel nested map or topic?



Vriendelijke groet / Kind regards,
Wim Hooghwinkel




Join to automatically receive all group messages.