Schematron to comment out a set of nodes
Here should go questions about transforming XML with XSLT and FOP.
-
- 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.
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.
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>
Code: Select all
<!--
-->
Scott Hudson
Staff Content Engineer
Site: docs.servicenow.com
Staff Content Engineer
Site: docs.servicenow.com
-
- Posts: 159
- Joined: Mon Nov 24, 2014 1:49 pm
- Location: Greven/Germany
Re: Schematron to comment out a set of nodes
Hey Scott,
try this:
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
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>
Greetings,
Stefan
stefan-jung.org – Your DITA/DITA-OT XML consultant
-
- 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
Staff Content Engineer
Site: docs.servicenow.com
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Schematron to comment out a set of nodes
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.
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
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>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- 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
Staff Content Engineer
Site: docs.servicenow.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service