Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2011, 07:11 PM
Registered User
 
Join Date: Nov 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default converting Table XML to HTML

Hi,

I have the below XML table where i have to convert it to HTML. I need to consider the XML attributes to create my HTML table...


Can someone help me in XSLT creation..

<Table ID="Tab7" Float="Yes" Width="100" Style="Style1">
<Caption Language="En">
<CaptionNumber>Table 2.7</CaptionNumber>
<CaptionContent>
<SimplePara>My Table</SimplePara>
</CaptionContent>
</Caption>
<tgroup cols="2">
<colspec colnum="1" colname="c1" align="left" colwidth="37.64"/>
<colspec colnum="2" colname="c2" align="left" colwidth="62.36"/>
<thead>
<row>
<entry align="left" colname="c1"> <SimplePara>Employee Number</SimplePara>
</entry>
<entry align="left" colname="c2"> <SimplePara>Employee Name</SimplePara> </entry>
</row>
</thead>
<tbody>
<row> <entry align="left" colname="c1"> <SimplePara>1</SimplePara> </entry> <entry align="left" colname="c2"> <SimplePara>John</SimplePara> </entry> </row> <row> <entry align="left" colname="c1"> <SimplePara>2</SimplePara> </entry> <entry align="left" colname="c2"/> </row> <row> <entry align="left" colname="c1"> <SimplePara>3</SimplePara> </entry> <entry align="left" colname="c2"> <SimplePara>Tom</SimplePara> </entry> </row>
</tbody>
</tgroup>
<tfooter>
<SimplePara>My footer</SimplePara>
</tfooter>
</Table>



Thanks.
 
Old November 5th, 2011, 04:13 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Its really unclear how your html output should be. Please post the XSLT code tried with and the output html code you are expecting out of the posted XML.
__________________
Rummy
 
Old November 5th, 2011, 05:09 AM
Registered User
 
Join Date: Nov 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Output of XML (Expected result for problem)

Hi,

Here is the expected output. Also, i need to create the columns dynamically based on the tgroup element <tgroup cols="2">. Also, every <row> <entry align="left" colname="c1"> column name should map to the respective column. Here c1 should go in column1, c2 should display in 2nd column, etc..,


http://i39.tinypic.com/2cpaj9d.jpg

Thanks in advance...
 
Old November 5th, 2011, 08:32 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

The following code would give you an idea:
Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
 
<xsl:output method="html"/>
 
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
 
<xsl:template match="thead">
<th>
<xsl:apply-templates select="node()|@*"/>
</th>
</xsl:template>
 
<xsl:template match="row">
<tr>
<xsl:apply-templates select="node()|@*"/>
</tr>
</xsl:template>
 
<xsl:template match="entry">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
 
<xsl:template match="tfooter">
<tfoot>
<xsl:value-of select="."/>
</tfoot>
</xsl:template>
 
</xsl:stylesheet>
__________________
Rummy
 
Old November 5th, 2011, 01:37 PM
Registered User
 
Join Date: Nov 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for your help.. Will try this code and update..
 
Old November 10th, 2011, 09:36 PM
Registered User
 
Join Date: Nov 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Working Solution

I found the below solution which is similar to my problem...It worked !


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

<xsl:template match="TABLE">
<!-- skip HEADERROW -->
<xsl:apply-templates select="DATAROWS" />
</xsl:template>

<xsl:template match="DATAROWS">
<table>
<xsl:apply-templates select="preceding-sibling::HEADERROW" />
<xsl:apply-templates select="DATAROW[position() &gt;= 1]" />
</table>
</xsl:template>

<xsl:template match="HEADERROW | DATAROW">
<tr><xsl:apply-templates /></tr>
</xsl:template>

<xsl:template match="HEADER">
<th><xsl:value-of select="."/></th>
</xsl:template>

<xsl:template match="DATA">
<td><xsl:value-of select="."/></td>
</xsl:template>

</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting "TEX" equations in XML to HTML or XHTML kvbhaskar7 XSLT 1 November 2nd, 2011 04:26 AM
XML Table to Html JohnBampton XSLT 2 March 9th, 2009 08:54 AM
Converting a given string to html table in asp,net ostwald ASP.NET 2.0 Professional 2 September 10th, 2007 04:44 AM
converting self-nested xml to html its_vippy XSLT 1 June 1st, 2005 04:47 AM
problem while converting xml to html its_vippy XSLT 2 May 30th, 2005 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.