Schematron to comment out a set of nodes

Here should go questions about transforming XML with XSLT and FOP.
shudson310
Posts: 156
Joined: Sat Feb 26, 2005 12:09 am
Location: USA
Contact:

Schematron to comment out a set of nodes

Post 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.

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
Staff Content Engineer
Site: docs.servicenow.com
xephon
Posts: 134
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: Schematron to comment out a set of nodes

Post 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
stefan-jung.org – Your DITA/DITA-OT XML consultant
shudson310
Posts: 156
Joined: Sat Feb 26, 2005 12:09 am
Location: USA
Contact:

Re: Schematron to comment out a set of nodes

Post 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:

Code: Select all

<!--


-->
Scott Hudson
Staff Content Engineer
Site: docs.servicenow.com
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron to comment out a set of nodes

Post 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
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
shudson310
Posts: 156
Joined: Sat Feb 26, 2005 12:09 am
Location: USA
Contact:

Re: Schematron to comment out a set of nodes

Post by shudson310 »

Thanks, Octavian! That solution works perfectly for me.
Scott Hudson
Staff Content Engineer
Site: docs.servicenow.com
Post Reply