Inconsistent table structure after applying an XSLT on title element

Here should go questions about transforming XML with XSLT and FOP.
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Inconsistent table structure after applying an XSLT on title element

Post 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
image.png (59.26 KiB) Viewed 1236 times
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>
Last edited by gbv34 on Sat Aug 27, 2022 4:30 pm, edited 2 times in total.
------
Gaspard
Martin Honnen
Posts: 96
Joined: Tue Aug 19, 2014 12:04 pm

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

Post 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.
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

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

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

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

Post by gbv34 »

Thanks Radu :)
------
Gaspard
Post Reply