You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Vasanth Kumar Kumarswamy <va...@wipro.com> on 2000/11/02 04:03:31 UTC

Help required in XML to HTML Conversion... using XSL

Hi,

We are facing a problem in converting an XML document to HTML Document using XSL style sheets.
We have converted it to HTML without column headings.
(It is required to extract the tag names(column-1, column-2, column-3)  into <TH>column-1</TH>...
tags in the HTML output.

The sample XML will be as follows :

xml Structure :

<table_name>
   <Record>
       <column-1>Data1</column-1>
       <column-2>Data2</column-2>
       <column-3>Data3</column-3>
   </Record>
   . . . 
  </table_name>

We require the HTML Layout as follows :

HTML Structure:

<HTML>
 <HEAD>
  table_name
 </HEAD>
  <BODY>
     <TABLE>
        <TH>column-1</TH>
        <TH>column-2</TH>
        <TH>column-3</TH>
        <TR>
            <TD>Data1</TD>
            <TD>Data2</TD>
            <TD>Data3</TD>
       </TR>
     </TABLE>
  </BODY>
</HTML>

We will be verymuch thankful if anyone provide us a solution.


Regards
Vasanth


Re: Help required in XML to HTML Conversion... using XSL

Posted by Jim Melton <ja...@cylogix.com>.
Consider:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="1.0">

  <xsl:strip-space elements="*"/>

  <!--output html-->
  <xsl:output method="html" media-type="text/html" indent="yes"/>

  <xsl:template match="/*">
    <HTML>
      <HEAD>
	<xsl:value-of select="name(.)"/>
      </HEAD>
      <BODY>
        <TABLE>
	  <xsl:apply-templates select="Record" mode="headings"/>
	  <xsl:apply-templates select="Record" mode="data"/>
        </TABLE>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="Record" mode="headings">
    <xsl:if test="position()=1">
      <xsl:for-each select="*">
        <TH><xsl:value-of select="name(.)"/></TH>
      </xsl:for-each>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Record" mode="data">
    <TR>
      <xsl:for-each select="*">
        <TD> <xsl:apply-templates/></TD>
      </xsl:for-each>
    </TR>
  </xsl:template>

</xsl:stylesheet>



Vasanth Kumar Kumarswamy wrote:
> 
> Hi,
> 
> We are facing a problem in converting an XML document to HTML
> Document using XSL style sheets.
> 

-- 
James Melton
CyLogix, Inc. 
(609) 750-5190 
http://www.cylogix.com

Re: Help required in XML to HTML Conversion... using XSL

Posted by Conny Krappatsch <co...@smb-tec.com>.
On Thu, 2 Nov 2000 11:03:31 +0800
"Vasanth Kumar  Kumarswamy" <va...@wipro.com> wrote:

Hi,

I got your mail five or four times, any reason for this?

However you get the name of an element using the name function, e.g.

<xsl:template match="column-1">
    <xsl:value-of select="name(.)"/>
</xsl:template>

produces the name of the <column-1> element, i.e. "column-1".

Hope that helps,
Conny Krappatsch

> Hi,
> 
> We are facing a problem in converting an XML document to HTML Document using XSL style sheets.
> We have converted it to HTML without column headings.
> (It is required to extract the tag names(column-1, column-2, column-3)  into <TH>column-1</TH>...
> tags in the HTML output.
> 
> The sample XML will be as follows :
> 
> xml Structure :
> 
> <table_name>
>    <Record>
>        <column-1>Data1</column-1>
>        <column-2>Data2</column-2>
>        <column-3>Data3</column-3>
>    </Record>
>    . . . 
>   </table_name>
> 
> We require the HTML Layout as follows :
> 
> HTML Structure:
> 
> <HTML>
>  <HEAD>
>   table_name
>  </HEAD>
>   <BODY>
>      <TABLE>
>         <TH>column-1</TH>
>         <TH>column-2</TH>
>         <TH>column-3</TH>
>         <TR>
>             <TD>Data1</TD>
>             <TD>Data2</TD>
>             <TD>Data3</TD>
>        </TR>
>      </TABLE>
>   </BODY>
> </HTML>
> 
> We will be verymuch thankful if anyone provide us a solution.
> 
> 
> Regards
> Vasanth
> 
> 


--