XSL template for part element transformation

Post here questions and problems related to editing and publishing DITA content.
gbv34
Posts: 81
Joined: Thu Jan 20, 2022 12:36 pm

XSL template for part element transformation

Post by gbv34 »

Hello,

I currently have a document that uses a part element that includes a topicmeta, a chapter and a topicref. My customer used a custom attribute and declared it in a dtd. However, I'm looking a way to insert it in an xhtml output. But for that, I need to find the XSL template used for the transformation.

So far, my source looks like this:

Code: Select all

<bookmap xml:lang="en" id="GUID-87F37878-D357-439F-9794-EF55A04B5491"
	xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/">
	<booktitle>
		<booklibrary>Rules for</booklibrary>
		<mainbooktitle>Materials and Welding</mainbooktitle>
	</booktitle>

	<part divisionLabel="2" id="GUID-EF333DD9-43C5-436E-AF90-837C22029056">
		<topicmeta>
			<navtitle>Materials</navtitle>
		</topicmeta>
		<chapter id="GUID-D3E288B0-C90C-464A-8C03-17FA3B4BB31A">
			<topicref
				href="topic1.xml"
				id="GUID-1202A1BF-32B3-440B-88D7-2756FFBEF1E3"/>
		
		</chapter>
	</part>
	</bookmap>
I have been looking into the topicmergeImpl.xsl but got no success in transforming one of its templates:

Code: Select all

 <xsl:template match="*[contains(@class,' map/topicref ')]" mode="build-tree">
        <xsl:choose>
            <xsl:when test="not(normalize-space(@first_topic_id) = '')">
                <xsl:apply-templates select="key('topic',@first_topic_id)">            
                    <xsl:with-param name="parentId" select="generate-id()"/>
                </xsl:apply-templates>
                <xsl:if test="@first_topic_id != @href">
                    <xsl:apply-templates select="key('topic',@href)">            
                        <xsl:with-param name="parentId" select="generate-id()"/>
                    </xsl:apply-templates>
                </xsl:if>
            </xsl:when>
            <xsl:when test="not(normalize-space(@href) = '')">
                <xsl:apply-templates select="key('topic',@href)">            
                    <xsl:with-param name="parentId" select="generate-id()"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="contains(@class, ' bookmap/part ') or
                (normalize-space(@navtitle) != '' or *[contains(@class,' map/topicmeta ')]/*[contains(@class,' topic/navtitle ')])">
                <xsl:variable name="isNotTopicRef" as="xs:boolean">
                    <xsl:call-template name="isNotTopicRef"/>
                </xsl:variable>
              
                <xsl:if test="not($isNotTopicRef)">
                    <topic id="{generate-id()}" class="+ topic/topic pdf2-d/placeholder ">
                        <title class="- topic/title ">
                            <xsl:choose>
                                <xsl:when test="*[contains(@class,' map/topicmeta ')]/*[contains(@class,' topic/navtitle ')]">
                                    <xsl:copy-of select="*[contains(@class,' map/topicmeta ')]/*[contains(@class,' topic/navtitle ')]/node()"/>coucouCOUOCOUCOUCOUUCUCOCC
                                </xsl:when>
                                <xsl:when test="@navtitle">
                                    <xsl:value-of select="@navtitle"/>
                                </xsl:when>
                            </xsl:choose>
                        </title>
                        <!--body class=" topic/body "/-->
                        <xsl:apply-templates mode="build-tree"/>
                    </topic>
                </xsl:if>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates mode="build-tree"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
Would you have any pointers about a relevant template that would access the part transformation?
Thanks for any tips :)
------
Gaspard
Radu
Posts: 8283
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSL template for part element transformation

Post by Radu »

Hi Gaspard,

So you seem to be interested in the HTML-based outputs, right?
The "topicmergeImpl.xsl" is from what I know used only in the PDF based output when the DITA Map's topicrefs are expanded in one large XML document which later is converted to PDF.
For example both for XHTML and HTML5 publishing, the DITA Map is processed with an XSLT stylesheet to produce the index.html. Each DITA topic is processed with another XSLT stylesheet to produce an HTML file from each. The XSLT processing used for topics does not have direct access to the DITA Map contents.
The XSLT which is applied on the DITA Map to produce for example the XHTML output is located in "OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT3.x/plugins/org.dita.xhtml/xsl/map2xhtml-cover.xsl".
There is an extension point which can be used by a plugin to contribute an XSLT stylesheet to customize the TOC generation:
https://www.dita-ot.org/dev/extension-p ... tml5.cover

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 81
Joined: Thu Jan 20, 2022 12:36 pm

Re: XSL template for part element transformation

Post by gbv34 »

Thank you, Radu.
I used this template and edited it to display the attribute I wanted to insert in my XHTML output.
This worked fine :)

Code: Select all

<xsl:template match="*[contains(@class, ' map/map ')]" mode="toc">
        <xsl:param name="pathFromMaplist"/>
        <xsl:param name="divLabel">
            <xsl:value-of select=".//part/@divisionLabel"/>
        </xsl:param>
        <xsl:if test="descendant::*[contains(@class, ' map/topicref ')]
            [not(@toc = 'no')]
            [not(@processing-role = 'resource-only')]">

            <span>
                <xsl:attribute name="divisionLabel" select="$divLabel"/>
                <ul class="coucou">
                    <xsl:call-template name="commonattributes"/>
                    <xsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="toc">
                        <xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
                    </xsl:apply-templates>
                </ul>
            </span>
        </xsl:if>
    </xsl:template>
    
------
Gaspard
Post Reply