0
votes

I am transforming a document trying to provide templates to all used elements, and catching the ones I might miss with a "catch all others filter". This works mostly as expected, and I can create a lot of elements with the correct attributes, but I get into trouble with one special attribute - "valign". Everything else works in the supplied code.

I originally included all matches that were supposed to be copied in one template, but here I have tried splitting my xslt match up into different templates, but I still get the same result (which was expected but hey, I had to try...). When I use the XMLSpy debugger, the transform also works.

Source xml snippet:

<?xml version="1.0" encoding="UTF-8"?>
    <content>
                <table tocentry="1">
                    <tgroup align="left" char="" charoff="50" cols="2">
                        <colspec colname="colspec0" colwidth="1*"/>
                        <colspec colname="colspec1" colwidth="1.5*"/>
                        <tbody valign="top">
                            <row>
                                <entry morerows="0" rotate="0" valign="top">
                                    <para>Volume washing fluid</para>
                                </entry>
                                <entry morerows="0" rotate="0" valign="top">
                                    <para>3 dmĀ³</para>
                                </entry>
                            </row>
                        </tbody>
                    </tgroup>
                </table>
    </content>
</dmodule>

XSLT 2.0 snippet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="fo xs fn">
<xsl:output encoding="utf-8" indent="yes" method="xml"/>


    <xsl:template match="@*|*">
        <xsl:comment>warning, node not handled by defined templates: "<xsl:copy-of select="local-name()"/>"</xsl:comment>
    </xsl:template>

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


<!--**************************************************-->
<!-- ************** Common                    ********-->
<!--**************************************************-->

    <xsl:template match="table | 
                            tgroup | 
                            tbody | 
                            colspec | 
                            row | 
                            entry | 
                            figure | 
                            para[not(parent::note or parent::warning or parent::caution or following-sibling::seqlist)] | 
                            legend | 
                            note | 
                            title | 
                            warning | 
                            caution | 
                            note
                            ">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="@align |
                            @char |
                            @charoff |
                            @colname |
                            @cols |
                            @colwidth |
                            @id |
                            @morerows |
                            @tocentry |
                            @valign">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

I want this to work as an identity transform. The only way I can get around this is to use a "copy-of" when I find a table element.

Error message in XMLSpy (set up with Saxon) is the following: Error evaluating ((attr{xsi:noNamespaceSchemaLocation=...}, ...)) on line 146 column 26 of basics_001.xsl: XTDE0410: An attribute node (valign) cannot be created after a child of the containing element. Most recent element start tag was output at line 131 of module basics_001.xsl In template rule with match="@valign" on line 144 of basics_001.xsl invoked by xsl:apply-templates at file:/C:/basics_001.xsl#131 In template rule with match="entry" on line 129 of basics_001.xsl invoked by xsl:apply-templates at ....

1

1 Answers

0
votes

I think your approach to output a comment as a child node for attributes not being matched elsewhere is casusing the problem; you will need to use xsl:message to output information about not-matched nodes. Clearly if the rotate attribute results in a child comment output you can't expect to be able to output any attribute node (like valign) afterwards.