Page 1 of 1
Schematron to comment out a set of nodes
Posted: Sun Dec 18, 2016 10:18 pm
by shudson310
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.
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.
Re: Schematron to comment out a set of nodes
Posted: Mon Dec 19, 2016 1:35 am
by xephon
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
Re: Schematron to comment out a set of nodes
Posted: Mon Dec 19, 2016 7:31 am
by shudson310
The problem that I'm running into is that the markup is not preserved within the comment. With your solution, I still get:
Re: Schematron to comment out a set of nodes
Posted: Mon Dec 19, 2016 2:55 pm
by tavy
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"><!--</xsl:text>
<xsl:copy-of select="."/>
<xsl:text disable-output-escaping="yes">--></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
Re: Schematron to comment out a set of nodes
Posted: Mon Dec 19, 2016 5:18 pm
by shudson310
Thanks, Octavian! That solution works perfectly for me.