RE: [xsl] Re: Formatting issue with HTML and TEXT output method

Subject: RE: [xsl] Re: Formatting issue with HTML and TEXT output method
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 17 Jul 2008 18:08:31 +0100
> Here is my sample xslt and xml .

You still haven't indicated what output you want.

> html.xsl
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:output method="html" omit-xml-declaration="no" indent="yes"/>
> 
> <xsl:template match="/content">
> 	<xsl:copy>
> 		<xsl:apply-templates/>
> 	</xsl:copy>
> </xsl:template>

This template rule will never be fired because your code never does an
xsl:apply-templates call.
> 
> <xsl:template match="/">
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <meta http-equiv="Content-Type" content="text/html; 
> charset=UTF-8"/> 

You shouldn't try to output a <meta> element, the HTML output method takes
care of that.

<title></title> </head> <body> <table 
> width="100%"  valign="top"> <tr> <td colspan="2" 
> style="text-align:justify;"> <xsl:value-of select="//name"/> 

It's better to select the name explicitly as select="/content/name".

> </td></tr> <tr> <td colspan="2" style="text-align:justify;"> 
> <xsl:copy-of select="//cond"/>

There's no such element as <cond> in HTML. Also, your <cond> element
contains an <html> element. So you're going to generate the structure:

<html>
  <body>
    <table>
      <tr>
        <td>
          <cond>
            <html>
              <body>
                <p>

This is not legal HTML, and I have no idea what the browser will do with it.

> 
> text.xsl

I really can't guess what output you are trying to produce with this code.
Generally if you output element nodes and then serialize using the text
output method, there's probably something wrong.

Michael Kay
http://www.saxonica.com/


> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:output method="text" encoding="UTF-8" />
> 
> <xsl:template match="/content">
> 	<xsl:copy>
> 		<xsl:apply-templates />
> 	</xsl:copy>
> </xsl:template>
> <xsl:template match="/">
> NAME <xsl:value-of select="//name"/>
> <xsl:copy-of select="//cond"/>
> </xsl:template>
> </xsl:stylesheet>
> 
> 
> content.xml
> 
> 
> <content>
> <name>
> Senthil
> </name>
> <cond>
> <html>
> <body>
> <p align="center">
> TESTTESTTESTTESTTESTTESTTESTTESTTEST
> TESTTESTTESTTESTTESTTESTTESTTESTTEST
> TESTTESTTESTTESTTESTTESTTESTTESTTEST
> </p>
> <p align="center">
> TESTTESTTESTTESTTESTTESTTESTTESTTEST
> TESTTESTTESTTESTTESTTESTTESTTESTTEST
> TESTTESTTESTTESTTESTTESTTESTTESTTEST
> </p>
> </body>
> </html>
> </cond>
> </content>
> 
> 
> Thanks,
> Senthil
> 
> On Wed, Jul 16, 2008 at 4:38 PM, Senthilkumaravelan K 
> <skumaravelan@xxxxxxxxxxxxxx> wrote:
> > Hi All,
> > We have xml
> > <note>
> > <cond>
> > <html>
> > <body>
> > <p align="center">
> > TESTTESTTESTTESTTESTTESTTESTTESTTEST
> > TESTTESTTESTTESTTESTTESTTESTTESTTEST
> > TESTTESTTESTTESTTESTTESTTESTTESTTEST
> > </p>
> > <p align="center">
> > TESTTESTTESTTESTTESTTESTTESTTESTTEST
> > TESTTESTTESTTESTTESTTESTTESTTESTTEST
> > TESTTESTTESTTESTTESTTESTTESTTESTTEST
> > </p>
> > </body>
> > </html>
> > </cond>
> > <note>
> >
> > When we write xslt one with "html" as output method and 
> text as output method.
> >
> > for html out method am using
> > <xsl:value-of select="//cond">
> >
> > text output method
> > <xsl:copy-of select="//cond">
> >
> >
> > How to make the text xslt output like formatted text output pretty 
> > with alignment.
> >
> > Any idea would of great help.
> >
> > Thanks
> > Senthil

Current Thread