[jdom-interest] Help with <xsl:text disable-output-escaping="yes">

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Sep 17 07:42:30 PDT 2002


Hi,

Attached is a proposal for adding support for automatically disabling/enabling 
character escaping when the <?javax.xml.transform.disable-output-escaping?> 
and <?javax.xml.transform.enable-output-escaping?> PIs are encountered.

With this patch, the element <root>:
          Element  root = new Element("root");
          root.addContent("a, b & c");
          root.addContent(
             new ProcessingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, ""));
          root.addContent("<foo id=\"bar\"><bar>");
          root.addContent(
             new ProcessingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, ""));
          root.addContent("It's raining cats & dogs");
          root.addContent(
             new ProcessingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, ""));
          root.addContent("</bar></foo>");
          root.addContent(
             new ProcessingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, ""));
          root.addContent("x < z > y");

outputs as:

<root>
   a, b &amp; c
   <foo id="bar"><bar>
   It's raining cats &amp; dogs
   </bar></foo>
   x &lt; z &gt; y
</root>

Laurent


Emmett McLean wrote:
> Hi,
> 
> It appears what disable-output-escaping works in xalan
> but not in JDOM. I wonder you know of a way to enable it?
> 
> I have an XSLT which works fine with an XML file if I
> do the transformation on the command line using xalan.
> 
> However, when I do the transform in JDOM the following code
> which works OK in xalan ...
> 
> <xsl:text disable-output-escaping="yes">
> <![CDATA[
> <style type="text/css">
> <!--
> body { font-family: Arial, Verdana, sans-serif; background-color: #FFFFFF}
> -->
> </style>
> ]]>
> </xsl:text>
> 
> Gets rendered in JDOM as ...
> 
> <?javax.xml.transform.disable-output-escaping?>
> 
> &lt;style type="text/css"&gt;
> &lt;!--
> body { font-family: Arial, Verdana, sans-serif; background-color: #FFFFFF}
> --&gt;
> &lt;/style&gt;
> 
> 
> In otherwords the disable-output-escaping tag fails.
> 
> I can email both the xsl and xml if someone would like to experiment.
> 
> Thanks,
> 
> em
-------------- next part --------------
Index: XMLOutputter.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/output/XMLOutputter.java,v
retrieving revision 1.83
diff -r1.83 XMLOutputter.java
61a62,63
> import javax.xml.transform.Result;
> 
214a217,220
>     /** Whether output escaping is enabled
>       * - default is <code>true</code> */
>     private boolean escapeOutput = true;
> 
686c692,693
<                 printProcessingInstruction((ProcessingInstruction) obj, out);
---
>                 printProcessingInstruction((ProcessingInstruction) obj,
>                                                                 out, true);
806c813
<         printProcessingInstruction(pi, out);
---
>         printProcessingInstruction(pi, out, false);
1063a1071,1076
>      * @param process <code>boolean</code> whether to process the
>      *        processing instruction if its target is well-known.
>      *        Processed PIs are removed from the output document.
>      *
>      * @see Result#PI_ENABLE_OUTPUT_ESCAPING
>      * @see Result#PI_DISABLE_OUTPUT_ESCAPING
1066c1079,1080
<                                               Writer out) throws IOException {
---
>                                               Writer out, boolean process)
>                        throws IOException {
1068c1082
<         String rawData = pi.getData();
---
>         boolean piProcessed = false;
1070,1081c1084,1109
<         // Write <?target data?> or if no data then just <?target?>
<         if (!"".equals(rawData)) {
<             out.write("<?");
<             out.write(target);
<             out.write(" ");
<             out.write(rawData);
<             out.write("?>");
<         }
<         else {
<             out.write("<?");
<             out.write(target);
<             out.write("?>");
---
>         if (process) {
>            if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING)) {
>               escapeOutput = false;
>               piProcessed  = true;
>            }
>            else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING)) {
>               escapeOutput = true;
>               piProcessed  = true;
>            }
>         }
>         if (piProcessed == false) {
>             String rawData = pi.getData();
> 
>             // Write <?target data?> or if no data then just <?target?>
>             if (!"".equals(rawData)) {
>                 out.write("<?");
>                 out.write(target);
>                 out.write(" ");
>                 out.write(rawData);
>                 out.write("?>");
>             }
>             else {
>                 out.write("<?");
>                 out.write(target);
>                 out.write("?>");
>             }
1309c1337,1338
<                 printProcessingInstruction((ProcessingInstruction)next, out);
---
>                 printProcessingInstruction((ProcessingInstruction)next,
>                                                                 out, true);
1705a1735,1736
>         if (escapeOutput == false) return str;
> 


More information about the jdom-interest mailing list