xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Baptiste Burgaud" <...@teamlog.fr>
Subject Re: Inserting HTML into the result tree
Date Thu, 02 Aug 2001 08:21:21 GMT
Hi Victor,

I'm not sure of what you want to do (and how...) but this may help:

"maBelleBaliseRawHTML" template allow non XHTML output and the "par"
template shows how to create your own tag without the xsl:element
instruction (it actually creates an HTML comment as the xsl:comment tag does
not seems to work when outputing html)

File helloWorld.java:
// compilation: javac -classpath
".;d:\tmp;d:\tmp\xalan-j_2_0_1\bin\xalan.jar" %f
// execution: java -classpath ".;d:\tmp;d:\tmp\xalan-j_2_0_1\bin\xalan.jar"
HelloWorld

import javax.xml.transform.*;
import javax.xml.transform.stream.*;

import java.io.*;

public class HelloWorld
{
 public static void main(String[] args)
    throws TransformerException, TransformerConfigurationException,
           FileNotFoundException, IOException
  {
   TransformerFactory tFactory = TransformerFactory.newInstance();
   Transformer transformer = tFactory.newTransformer(new
StreamSource("helloWorld.xsl"));
   transformer.transform(new StreamSource("helloWorld.xml"), new
StreamResult(new FileOutputStream("helloWorld.html")));

   System.out.println("************* The result is in helloWorld.html
*************");
  }
}


File helloWorld.xsl:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method = "html"/>
<xsl:comment>this won't output anything!</xsl:comment>

  <xsl:template match="monBeauDocument">
    <HTML>
      <HEAD>
        <TITLE><xsl:value-of select="monBeauTitre"/></TITLE>
      </HEAD>
      <BODY>
        <center>hello</center>
        <xsl:apply-templates select="maBelleBaliseRawHTML"/>
        <xsl:apply-templates select="par"/>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="maBelleBaliseRawHTML">
    <xsl:value-of disable-output-escaping="yes" select="."/>
  </xsl:template>

  <xsl:template match="par">
  <H4>
    <xsl:text disable-output-escaping="yes"><![CDATA[<!--]]></xsl:text>
      <xsl:value-of select="@id"/>
    <xsl:text disable-output-escaping="yes"><![CDATA[-->]]></xsl:text>
    <xsl:value-of select="."/>
  </H4>
  </xsl:template>

</xsl:stylesheet>

File helloWorld.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<monBeauDocument>
  <monBeauTitre>
    Hello World
  </monBeauTitre>
  <par id="123">
    un beau paragraphe
  </par>
  <maBelleBaliseRawHTML>
    <![CDATA[
      <ul>
        <li>coucou<br>
        <li>&amp;YOUHOU<BR>
      </ul>
    ]]>
  </maBelleBaliseRawHTML>
</monBeauDocument>



----- Original Message -----
From: "Victor M. Moreno" <vmoreno@germinus.com>
To: <general@xml.apache.org>
Sent: Thursday, August 02, 2001 9:37 AM
Subject: Re: Inserting HTML into the result tree


> Thanks Gary,
> can you show me any sample in the xalan package?
>
> regards
>
> Victor
>
>
> > "Victor M. Moreno" wrote:
> > > Does the xsl extension element have to return a nodeset instead of a
> String
> > > as I am doing
> > > right now?
> >
> > Yes.
> >
> > ---------------------------------------------------------------------
> > In case of troubles, e-mail:     webmaster@xml.apache.org
> > To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> > For additional commands, e-mail: general-help@xml.apache.org
>
>
> ---------------------------------------------------------------------
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message