You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by David Bigwood <Da...@chordiant.com> on 2001/05/21 16:14:39 UTC

Returning HTML String intact from Extension Function

I have a problem running a Java extension function from an XSL stylesheet in
Xalan.
The Java Class I am calling returns me a String, which contains HTML tags.
I wish to use the HTML as supplied to change the output of the XSL
stylesheet.

Unfortunately, I believe the string is escaped as/before it is returned to
me and instead of getting, e.g.

<h1>Hello</h1>

I get something like:

&lt;h1&gt;Hello&lt;/h2&gt;

Does anyone know how I can stop the string being encoded and/or make use of
the HTML as HTML?

Thanks in advance
-David


----
David Bigwood
Principal Design Engineer
Chordiant Software, Inc.
T: 603-621-4332
F: 603-621-4330
http://www.chordiant.com
Chordiant Software - Intelligent Customer Interaction Management


Re: Returning HTML String intact from Extension Function

Posted by jason heddings <Ja...@Sun.COM>.
-- 

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      \\\|///                 Jason Heddings             ((
     \\ ~ ~ //                303.272.5166 (x75166)    C|~~|
     (/ @ @ /)                Jason.Heddings@Sun.COM    `__'
 ~~oOOo~(_)~oOOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: Returning HTML String intact from Extension Function

Posted by jason heddings <Ja...@Sun.COM>.
(Apologies for that empty message...)

David-

As Gary said, the best thing to do is to return the <H1> tag itself,
however I ran into a situation where I needed to include the contents of
an HTML file that was not well-formed XHTML.  Here's the way to
accomplish this:

There is a supported way to mimic the <xsl:value-of ...
disable-output-escaping="yes" /> behavior in extensions.  Here's the
code to do this:

        try {
            if ( disableOutputEscape ) {
                context.outputToResultTree( context.getStylesheet( ) ,
                  elementFactory.createProcessingInstruction(
                    Result.PI_DISABLE_OUTPUT_ESCAPING , null ) ) ;
            }

            context.outputToResultTree( style , content ) ;

            if ( disableOutputEscape ) {
                context.outputToResultTree( context.getStylesheet( ) ,
                  elementFactory.createProcessingInstruction(
                    Result.PI_ENABLE_OUTPUT_ESCAPING , null ) ) ;
            }
        } catch ( java.net.MalformedURLException mue ) {
        } catch ( java.io.FileNotFoundException fnfe ) {
        } catch ( java.io.IOException ioe ) {
        }

The variable "disableOutputEscape" is determined by the value of an
attribute in the extension function, "style" is the Stylesheet being
used (determined by context.getStylesheet( )), "content" is a String of
the content I want to send, and "elementFactory" is (an inappropriate
name for) a DOM Document object simply used to create the processing
instructions.  "Result" is javax.xml.transform.Result.

HTH,
--Jason



David Bigwood wrote:
> 
> I have a problem running a Java extension function from an XSL stylesheet in
> Xalan.
> The Java Class I am calling returns me a String, which contains HTML tags.
> I wish to use the HTML as supplied to change the output of the XSL
> stylesheet.
> 
> Unfortunately, I believe the string is escaped as/before it is returned to
> me and instead of getting, e.g.
> 
> <h1>Hello</h1>
> 
> I get something like:
> 
> &lt;h1&gt;Hello&lt;/h2&gt;
> 
> Does anyone know how I can stop the string being encoded and/or make use of
> the HTML as HTML?
> 
> Thanks in advance
> -David
> 
> ----
> David Bigwood
> Principal Design Engineer
> Chordiant Software, Inc.
> T: 603-621-4332
> F: 603-621-4330
> http://www.chordiant.com
> Chordiant Software - Intelligent Customer Interaction Management

-- 

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      \\\|///                 Jason Heddings             ((
     \\ ~ ~ //                303.272.5166 (x75166)    C|~~|
     (/ @ @ /)                Jason.Heddings@Sun.COM    `__'
 ~~oOOo~(_)~oOOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: Returning HTML String intact from Extension Function

Posted by Gary L Peskin <ga...@firstech.com>.
David Bigwood wrote:
> 
> I have a problem running a Java extension function from an XSL stylesheet in
> Xalan.
> The Java Class I am calling returns me a String, which contains HTML tags.
> I wish to use the HTML as supplied to change the output of the XSL
> stylesheet.
> 
> Unfortunately, I believe the string is escaped as/before it is returned to
> me and instead of getting, e.g.
> 
> <h1>Hello</h1>
> 
> I get something like:
> 
> &lt;h1&gt;Hello&lt;/h2&gt;
> 
> Does anyone know how I can stop the string being encoded and/or make use of
> the HTML as HTML?
> 
> Thanks in advance
> -David

Return what you'd like to see in the output.  Namely, an <h1> element
node with a "Hello" text node child.

Gary