Page 1 of 1

Inconsistent table structure after applying an XSLT on title element

Posted: Sat Aug 13, 2022 10:51 pm
by gbv34
Hello!
I'm currently working on a plugin that replaces the values of outputclass attributes for different elements in a dita source.
The XSLT itself works as expected when I test it solely, but once I integrate it in my plugin with a feature extension="dita.xsl.html5" and launch an HTML5 transformation, I got strange results in the structure of the table.

As shown here, the display seems correct (besides the border) and the content is ordered.
image.png
I don't get why the structure of the table is not respected. Would you have any idea?
First, here is the XSLT used:

Code: Select all

<?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:xd="http://www.oxygenxml.com/ns/doc/xsl"
    exclude-result-prefixes="xs xd"
    version="2.0">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:param name="t-link" select="'ft-expanding-block-link'"/>
        <xsl:param name="t-block" select="'ft-expanding-block'"/>
        
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        
        <xsl:template match="*[@outputclass='collapse-folded']">
            <xsl:variable name="id-value" select="@id"/>        
            <xsl:element name="{name()}">    
                <xsl:copy-of select="@*[name()!='outputclass']"/> 
                <xsl:attribute name="class">
                    <xsl:value-of select="$t-block"/>
                </xsl:attribute>
                <xsl:if test="title">
                    <xsl:element name="span">
                        <xsl:attribute name="class"><xsl:value-of select="$t-link"/></xsl:attribute>
                        <xsl:attribute name="data-target-id"><xsl:value-of select="$id-value"/></xsl:attribute>
                        <xsl:value-of select="title"/>
                    </xsl:element>
                </xsl:if>
                                <xsl:copy-of select="node()[name()!='title']"/>
            </xsl:element>
        </xsl:template>
</xsl:stylesheet>

Re: Inconsistent table structure after applying an XSLT on title element

Posted: Sun Aug 14, 2022 12:52 pm
by Martin Honnen
What kind of view is that, are you using a browser's developer console where you inspect the rendered document tree after the browser parsed your input document as HTML5? HTML has rules to fix the parse tree e.g. a HTML span doesn't belong into a HTML table element, nor are there HTML row elements (HTML names them "tr" elements).
So in terms of XSLT and the result I would first look in oXygen at the transformation output, if the browser console shows your input tree is altered during parsing then you will need to fix your XSLT to output HTML5 according to the HTML5 syntax rules.

Re: Inconsistent table structure after applying an XSLT on title element

Posted: Mon Aug 15, 2022 7:34 am
by Radu
Hi,

When your XSLT is part of a DITA OT plugin, it is just a module, you should probably remove from it the xsl:output and the copy template:

Code: Select all

        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
So let your custom XSLT focus only on the element that it needs to change.

Regards,
Radu

Re: Inconsistent table structure after applying an XSLT on title element

Posted: Wed Aug 31, 2022 9:53 pm
by gbv34
Thanks Radu :)