Schematron to comment out a set of nodes

Here should go questions about transforming XML with XSLT and FOP.
shudson310
Posts: 113
Location: USA

Schematron to comment out a set of nodes

Sun Dec 18, 2016 10:18 pm

I'm trying to create a quick fix to take a selected set of nodes and add XML comments around them. I can't seem to get the nodes to copy into the body of the comment.

Code: Select all

<sqf:fix id="commentElement">
                <sqf:description>
                    <sqf:title>Comment out the element.</sqf:title>
                </sqf:description>
                <sqf:add node-type="comment" select="child::*" />
</sqf:fix>


When applied, this quick fix results in an empty comment, instead of the XML that was commented out.

Code: Select all

<!--
         
      -->


I would think there's a way to do this, but haven't found it. I've tried using <xsl:copy-of> and some variations on <sqf:replace>, but still not working.
Scott Hudson
Content Strategist
Jeppesen
Site: jeppesen.com
xephon
Posts: 96
Location: Münster/Germany

Re: Schematron to comment out a set of nodes

Mon Dec 19, 2016 1:35 am

Hey Scott,

try this:

Code: Select all

<sch:pattern id="comment">
        <sch:rule context="*[contains(@class, ' topic/p ')]">
            <sch:report test="contains(text(), 'foo')" sqf:fix="comment">
                Don't use paragraphs
            </sch:report>
            <sqf:fix id="comment">
                <sqf:description>
                    <sqf:title>Comment</sqf:title>
                </sqf:description>
                <sqf:replace match="." select="." node-type="comment"/>
            </sqf:fix>
        </sch:rule>
    </sch:pattern>


If you add a <p>foo</p> snippet, the report should be fired and the <sqf:replace> can be used to comment the <p> element.

Greetings,
Stefan
Join the DOCTALES DITA development team :arrow: https://doctales.atlassian.net/wiki
shudson310
Posts: 113
Location: USA

Re: Schematron to comment out a set of nodes

Mon Dec 19, 2016 7:31 am

The problem that I'm running into is that the markup is not preserved within the comment. With your solution, I still get:

Code: Select all

<!--


-->
Scott Hudson
Content Strategist
Jeppesen
Site: jeppesen.com
tavy
Posts: 144

Re: Schematron to comment out a set of nodes

Mon Dec 19, 2016 2:55 pm

Hello,

According to the SQF Specification , the content of the replace operation has the same functionality as the content of xsl:template element. The problem is that in XSLT when a comment is generated its content must be only text. XSLT Specification says: "It is an error if instantiating the content of xsl:comment creates nodes other than text nodes."

Therefore, using an SQF fix you cannot generate a comment that will contain markup.
As an workaround you can use the "xsl:text" with " disable-output-escaping" to generate the start and end of the comment. In this way you can generate also markup inside a comment.

Code: Select all

<sqf:replace>
    <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
        <xsl:copy-of select="."/>
    <xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
</sqf:replace>


I will add an issue on our issue tracker to analyze this problem. Maybe we can change the SQF implementation to allow generating a comment with markup in content.


Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
shudson310
Posts: 113
Location: USA

Re: Schematron to comment out a set of nodes

Mon Dec 19, 2016 5:18 pm

Thanks, Octavian! That solution works perfectly for me.
Scott Hudson
Content Strategist
Jeppesen
Site: jeppesen.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 1 guest