Tuesday, August 23, 2016

Converting Subject Scheme Map Values to a DITAVAL

Share to Facebook Share to Twitter Email This Share on Google Plus Share on Tumblr

Let's say you already have a Subject Scheme Map in your project and you use it to control attribute values: http://blog.oxygenxml.com/2015/07/controlled-attribute-values-for-your.html.

In the Oxygen Colors and Styles Preferences page you can also assign various colors and styles to each profiling attribute (name, value) combination. One option for this is to manually re-add attributes and values in that list. Another option would be to create an XSLT stylesheet to gather all profiling attribute names and values from the Subject Scheme map and create a DITAVAL file. The stylesheet would look like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <val>
            <xsl:for-each select="subjectScheme/enumerationdef">
                <!-- For each attribute name -->
                <xsl:if test="subjectdef/@keyref and attributedef/@name">
                    <xsl:variable name="attrName" select="attributedef/@name"/>
                    <xsl:variable name="keyref" select="subjectdef/@keyref"/>
                    <!-- For each key value -->
                    <xsl:for-each select="//*[@keys=$keyref]/*//@keys">
                        <xsl:variable name="attributeValue" select="."/>
                        <prop action="flag" att="{$attrName}" val="{$attributeValue}"/>
                    </xsl:for-each>
                </xsl:if>
            </xsl:for-each>
        </val>
    </xsl:template>
</xsl:stylesheet>

After you obtain the DITAVAL, you can import it directly in the Colors and Styles preferences page. If the DITAVAL file has flagging information, that information will be directly used to style each attribute value.

A possibility to enhance this workaround is to specify profiling styles for each attribute value directly in the Subject Scheme map using the <data> element like:
<subjectdef keys="linux">
    <data name="color" value="yellow"/>
</subjectdef>
in which case the XSLT stylesheet would create the DITAVAL by picking colors directly from the Subject Scheme Map:
….….…....
<prop action="flag" att="{$attrName}" val="{$attributeValue}">
    <xsl:choose>
        <!-- Here you can also set flagging colors depending on the profiling attribute value -->
        <xsl:when test="data[@name='color']">
            <xsl:attribute name="color" select="data/@value"/>
        </xsl:when>
    </xsl:choose>
</prop>
….….….….
In this way your Subject Scheme Map will keep both the controlled attribute values and various colors and styles which can later be used to create a DITAVAL and either publish with those styles or import the DITAVAL in Oxygen in order to highilight various elements with various colors:https://www.oxygenxml.com/demo/Colors_and_Styles_for_Profiled_Content.html.