Search code examples
xsltdita

Audience value not exporting to output file in XSLT transform


I'm having trouble getting the value in the audience tag to appear in my output file while running an XSLT transform on a DITA map.

This is the snippet of my input with audience="Alaska":

<topicgroup>
            <topichead navtitle="Alaska Property and Casualty Adjuster Law" locktitle="yes" audience="Alaska">
                <topicgroup>
                    <mapref href="Qbank/maps/Adj_Unit_AK.ditamap" format="ditamap"/>
                </topicgroup>
            </topichead>
        </topicgroup>

Here's the portion of my XSLT script that contains the <!--Add audience--> section:

<xsl:template match="topichead">
        <xsl:param name="all_topic_refs" select="topicref[@type='topic' or @type='concept']" as="element()*"/>
        <xsl:param name="all_question_refs" select="topicref[@type='question']" as="element()*"/>
        <xsl:param name="all_exam_refs" select="topicref[@type='exam']" as="element()*"/>
        <xsl:param name="audience" select="topichead[@audience='property' or @type='concept']" as="element()*"/>
        <xsl:param name="all_exam_maps" select="descendant-or-self::examMap" as="element()*"/>
           
                <xsl:copy>
                    <xsl:attribute name="navtitle">
                        <xsl:choose>
                            <xsl:when test="navtitle">
                                <xsl:apply-templates select="navtitle"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="@navtitle"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    
                    <!--Add audience-->
                    
                    <xsl:attribute name="audience">                       
                          <xsl:value-of select="@audience"/>
                    </xsl:attribute>
                    
                    <xsl:apply-templates select="*[not(self::examMap[@assessment_type='test-exam-primary']) and not(self::navtitle)]">
                        <xsl:with-param name="all_topic_refs" select="$all_topic_refs"/>
                        <xsl:with-param name="all_question_refs" select="$all_question_refs"/>
                        <xsl:with-param name="all_exam_refs" select="$all_exam_refs"/>
                        <xsl:with-param name="all_exam_maps" select="$all_exam_maps"/>
                    </xsl:apply-templates>
                </xsl:copy>       
    </xsl:template>

The output is giving me this with empty quotes in the Audience tag:

<topichead navtitle="Alaska Property and Casualty Adjuster Law" audience="">
         <topicref href="questions/inslic_assess_Adj_AK.dita"/>
      </topichead>

It pulls over the navtitle correctly but I can't figure why it won't pull over the audience input. Any help would be most appreciated.

Here's the full input file:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE bookmap PUBLIC "-//OASIS//DTD DITA BookMap//EN" "bookmap.dtd" []>
<bookmap>
    <booktitle>
        <mainbooktitle>Property &amp; Casualty Insurance Adjuster Qbank</mainbooktitle>
    </booktitle>
    <bookmeta>
        <category>course</category>
        <!-- <category> will describe type of map it is (qbank, course w/final exam, final exam, etc) -->
        <prodinfo>
            <prodname>Insurance Adjuster Licensing</prodname>
            <vrmlist>
                <vrm version="2022"/>
            </vrmlist>
            <brand>lic</brand>
            <series>adjqbank</series>
        </prodinfo>
        <bookid>
            <bookpartno>00012345</bookpartno>
        </bookid>
    </bookmeta>

    <!--   
        # Transform Type: LMS_Transform
        # DITAVAL: USstate_National_Short_Adjuster_Digital_InsLic.ditaval
        # File Path to Final Zip: G:\Shared drives\DITA Zip Files\Insurance Licensing\Property & Casualty\20535_National Insurance Adjuster Solution
        # Reltable: N
        # Glossary notes: Y/N 
        # Run from main folder?: N
        # PDF: Standard
    -->


    <chapter href="Qbank/topics/Adj_Qbank_1.dita" locktitle="yes">

        <topicmeta>
            <navtitle>Property &amp; Casualty Insurance Adjuster</navtitle>
        </topicmeta>

        

        <topicgroup>
            <topichead navtitle="Introduction to Insurance" locktitle="yes">
                <topicgroup>
                    <mapref href="Qbank/maps/Adj_Unit_1.ditamap" format="ditamap"/>
                </topicgroup>
            </topichead>
        </topicgroup>

        <topicgroup>
            <topichead navtitle="Contracts" locktitle="yes">
                <topicgroup>
                    <mapref href="Qbank/maps/Adj_Unit_2.ditamap" format="ditamap"/>
                </topicgroup>
            </topichead>
        </topicgroup>

    </chapter>
    <chapter href="Qbank/topics/Adj_Qbank_State_Specific.dita" locktitle="yes">
        <topicmeta>
            <navtitle>State Regulations</navtitle>
        </topicmeta>
        <topicgroup>
            <topichead audience="Alabama" navtitle="Alabama Property and Casualty Adjuster Law" locktitle="yes">
                <topicgroup>
                    <mapref href="Qbank/maps/Adj_Unit_AL.ditamap" format="ditamap"/>
                </topicgroup>
            </topichead>
        </topicgroup>
        <topicgroup>
            <topichead navtitle="Alaska Property and Casualty Adjuster Law" locktitle="yes" audience="Alaska">
                <topicgroup>
                    <mapref href="Qbank/maps/Adj_Unit_AK.ditamap" format="ditamap"/>
                </topicgroup>
            </topichead>
        </topicgroup>
        <topicgroup>
            <topichead navtitle="Arizona Property and Casualty Adjuster Law" locktitle="yes" audience="Arizona">
                <topicgroup>
                    <mapref href="Qbank/maps/Adj_Unit_AZ.ditamap" format="ditamap"/>
                </topicgroup>
            </topichead>
        </topicgroup>
    </chapter>
</bookmap>

Here's the full script with the non-related stuff removed:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:functx="http://www.functx.com"
    xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"    
    exclude-result-prefixes="xs functx ditaarch" version="2.0">

    <xsl:import href="functx-1.0.xsl"/>
    <xsl:import href="new_topic_task.xsl"/>

    <xsl:param name="BASE_DIR"/>
    <xsl:param name="OUT_DIR"/>
    
    <xsl:output encoding="UTF-8" method="xml" indent="yes"
        doctype-public="-//OASIS//DTD DITA Map//EN" doctype-system="map.dtd"/>
    
    <xsl:strip-space elements="*"/>
    
    <!-- Create a global variable so that we can refer back to the supermap. -->
    <xsl:variable name="supermap" select="/supermap" as="element()*"/>
    
    <!-- Create a global variable so that we can refer back to the los. -->
    <xsl:variable name="los_summary" select="/supermap/los_summary" as="element()*"/>
    
    

    <xsl:template match="/">
        <xsl:apply-templates select="supermap"/>
    </xsl:template>
    
    

    <xsl:template match="supermap">
        <map>
            <xsl:attribute name="title">
                <xsl:value-of select="@title"/>
            </xsl:attribute>
            <xsl:attribute name="id">
                <xsl:value-of select="@id"/>
            </xsl:attribute>

            <!-- Handle topicheads. -->
            <xsl:apply-templates select="topichead"/>
            
            
            
            <!-- Create the final exam map outside all other topic heads. -->
            <xsl:apply-templates select="topichead[@unit_map_type='final-exam']/examMap">
                
            </xsl:apply-templates>

            <!-- Handle LOS. -->
            <xsl:apply-templates select="los_summary"/>

        </map>
    </xsl:template>
    
    
    
    <!-- Top level topichead. -->
    <xsl:template match="topichead">
        
        <!-- Made these parameters so that subordinate topicheads behave correctly...I think. -->
        <xsl:param name="all_topic_refs" select="topicref[@type='topic' or @type='concept']" as="element()*"/>
        <xsl:param name="all_question_refs" select="topicref[@type='question']" as="element()*"/>
        <xsl:param name="all_exam_refs" select="topicref[@type='exam']" as="element()*"/>
        <xsl:param name="audience" select="topichead[@audience='property' or @type='concept']" as="element()*"/>
        <!-- Added for QBank -->
        <xsl:param name="all_exam_maps" select="descendant-or-self::examMap" as="element()*"/>
        
        
        
        <!-- [SP] 2015-01-13: Don't display topichead in qbank output. -->
        <xsl:choose>
            <xsl:when test="@unit_map_type = 'qbank'">
                <xsl:apply-templates select="*[not(self::examMap[@assessment_type='test-exam-primary'])]">
                    <xsl:with-param name="all_topic_refs" select="$all_topic_refs"/>
                    <xsl:with-param name="all_question_refs" select="$all_question_refs"/>
                    <xsl:with-param name="all_exam_refs" select="$all_exam_refs"/>
                    <xsl:with-param name="all_exam_maps" select="$all_exam_maps"/>
                    
                </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy>
                    <xsl:attribute name="navtitle">
                        <xsl:choose>
                            <xsl:when test="navtitle">
                                <xsl:apply-templates select="navtitle"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="@navtitle"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    
                    <!--Add audience-->
                    
                    <xsl:attribute name="audience">                       
                          <xsl:value-of select="@audience"/>
                    </xsl:attribute>
                    
                    <xsl:apply-templates select="*[not(self::examMap[@assessment_type='test-exam-primary']) and not(self::navtitle)]">
                        <xsl:with-param name="all_topic_refs" select="$all_topic_refs"/>
                        <xsl:with-param name="all_question_refs" select="$all_question_refs"/>
                        <xsl:with-param name="all_exam_refs" select="$all_exam_refs"/>
                        <xsl:with-param name="all_exam_maps" select="$all_exam_maps"/>
                    </xsl:apply-templates>
                </xsl:copy>
                
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
    
    
    <xsl:template match="@*">
        <xsl:copy/>
    </xsl:template>

</xsl:stylesheet>

Solution

  • I will assume your XSLT stylesheet is applied at a certain stage from a plugin when publishing the DITA XML content using the DITA Open Toolkit. You can add an xsl:message inside the xsl:template which matches the topichead:

     <xsl:message><xsl:copy-of select="."/></xsl:message>
    

    Then look in the console output when publishing to see exactly on what XML element the template is applied. The DITA Open Toolkit publishing engine has a pre-processing step which applies filtering and removes all profiling attributes from all elements. https://www.dita-ot.org/dev/reference/preprocess-debugfilter.html

    To preserve the profiling attributes when publishing you need to specify a DITAVAL filter file which specifies that the profiling attributes should pass through to the published output. Something like:

    <val>
       <prop action="passthrough" att="audience"/>
    </val>
    

    https://www.oxygenxml.com/dita/1.3/specs/langRef/ditaval/ditaval-prop.html