You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Kumar, Senthil" <Se...@wfg.com> on 2000/10/10 23:40:39 UTC

XML to HTML using xsl

Hi,
   I am new to Xml and Xsl. I want to show the XML file below in tabular
format in HTML using xsl.

The xml file is :
  <?xml version="1.0" ?> 
  <objectId.OPER.A001>
  <Marks>
  <Mark>2</Mark> 
  <Sin>0.9092974268256817</Sin> 
 <Mark>2</Mark> 
  <Sin>0.774562456456826</Sin> 
   </Marks>
  </objectId.OPER.A001>
 
Mark and Sin should be the column heading of the table.

Can anyone help me out.

Senthil Kumar


Re: XML to HTML using xsl

Posted by Conny Krappatsch <co...@smb-tec.com>.
Kumar, Senthil wrote:
> Hi,
>    I am new to Xml and Xsl. I want to show the XML file below in tabular
> format in HTML using xsl.
> 
> The xml file is :
>   <?xml version="1.0" ?> 
>   <objectId.OPER.A001>
>   <Marks>
>   <Mark>2</Mark> 
>   <Sin>0.9092974268256817</Sin> 
>  <Mark>2</Mark> 
>   <Sin>0.774562456456826</Sin> 
>    </Marks>
>   </objectId.OPER.A001>
>  
> Mark and Sin should be the column heading of the table.

Try these templates in your stylesheet:

<xsl:template match="objectId.OPER.A001">
    <html>
        <body>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>

<xsl:template match="Marks">
    <table>
        <tr><th>Mark></th><th>Sin></th></tr>
        <xsl:apply-templates select="Mark"/>
    </table>
</xsl:template>

<xsl:template match="Mark">
    <tr>
        <td><xsl:value-of select="."/></td>
        <td><xsl:value-of select="following-sibling::Sin"/>/td>
</xsl:template>

For your example this should result in:

<table>
    <th><td>Mark</td><td>Sin</td></th>
    <tr><td>2</td><td>0.9092974268256817</td></tr>
    <tr><td>2</td><td>0.774562456456826</td></tr>
</table>

Was this your intention.

You may want to have a look at some XSL tutorials (If you didn't already.):

at W3C: http://www.w3.org/Style/XSL/#learning
at XML.com: http://www.xml.com/pub/Guide/Tutorials (not only XSL).

Have fun,
Conny




-- 
______________________________________________________________________
Conny Krappatsch                              mailto:conny@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com




RE: XML to HTML using xsl

Posted by Tako Schotanus <qu...@palacio-cristal.com>.
And the definition of this XML is already fixed?
Because it doesn't seem very well structured or suited for the data you are
trying to capture.
I do think that it is going to take a very convoluted XSLT stylesheet to do
wat you want (probably not impossible, just "ugly")
But then again I'm no expert :-)

> Hi,
>    I am new to Xml and Xsl. I want to show the XML file below in tabular
> format in HTML using xsl.
>
> The xml file is :
>   <?xml version="1.0" ?>
>   <objectId.OPER.A001>
>   <Marks>
>   <Mark>2</Mark>
>   <Sin>0.9092974268256817</Sin>
>  <Mark>2</Mark>
>   <Sin>0.774562456456826</Sin>
>    </Marks>
>   </objectId.OPER.A001>
>
> Mark and Sin should be the column heading of the table.
>
> Can anyone help me out.
>
> Senthil Kumar
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org