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 March 3rd, 2011, 07:32 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default How to colspan

Hi,

I'm in xsl new one. i want to merge colspan in xslt, can you help for this.

Here i pasted xml and html for your reference.

i convert xml to html, but in html i can't get colspan. below i pasted for two html output for your reference. first html output without colspan and second one colspan achievement.

XML Coding:
<table>
<tgroup cols="4" frame="all" rowsep="1" colsep="1">
<colspec colnum="1" colname="col1" colwidth="25*" align="left"/>
<colspec colnum="2" colname="col2" colwidth="25*" align="left"/>
<colspec colnum="3" colname="col3" colwidth="25*" align="left"/>
<colspec colnum="4" colname="col4" colwidth="25*" align="left"/>
<spanspec namest="col1" nameend="col2" spanname="sp1"/>
<thead valign="middle">
<row>
<entry align="center" spanname="sp1"><text>Col1 and Col2 Span</text></entry>
<entry align="center"><text>Col3</text></entry>
<entry align="center"><text>Col4</text></entry>
</row>
</thead>
<tbody valign="top">
<row>
<entry morerows="1"><text><emph face="B">Attributable</emph></text></entry>
<entry><text>WNEU</text></entry>
<entry><text>Full</text></entry>
<entry><text>Yes</text></entry>
</row>
<row>
<entry><text>WWDP</text></entry>
<entry><text>Minority</text></entry>
<entry><text>Yes</text></entry>
</row>
</tbody>
</tgroup>
</table>

Current Html Value:
HTML Code:
<table cellpadding="5" cellspacing="0" width="100%" style="border: 2px solid #000000;">
<thead valign="middle">
<tr align="left" style="border: 1px solid #000000; border-right: 2px solid #000000;">
<td align="center" colspan="sp1" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Col1 and Col2 Span</td>
<td align="center" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Col3</td>
<td align="center" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Col4</td>
</tr>
</thead>
<tbody valign="top">
<tr align="left" style="border: 1px solid #000000; border-right: 2px solid #000000;">
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="28">Attributable</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">WNEU</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Full</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Yes</td>
</tr>
<tr align="left" style="border: 1px solid #000000; border-right: 2px solid #000000;">
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">WWDP</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Minority</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Yes</td>
</tr>
</tbody>
</table>
Excepted Output:
HTML Code:
<table cellpadding="5" cellspacing="0" width="100%" style="border: 2px solid #000000;">
<thead valign="middle">
<tr align="left" style="border: 1px solid #000000; border-right: 2px solid #000000;">
<td align="center" colspan="2" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Col1 and Col2 Span</td>
<td align="center" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Col3</td>
<td align="center" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Col4</td>
</tr>
</thead>
<tbody valign="top">
<tr align="left" style="border: 1px solid #000000; border-right: 2px solid #000000;">
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="28">Attributable </td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">WNEU</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Full</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Yes</td>
</tr>
<tr align="left" style="border: 1px solid #000000; border-right: 2px solid #000000;">
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">WWDP</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Minority</td>
<td align="left" colspan="0" style="border: 2px solid #000000; border-right: 2px solid #000000;" rowspan="0">Yes</td>
</tr>
</tbody>
</table>
Kindly suggest for this.

Regards,
Rockbal

Last edited by RockBal; March 3rd, 2011 at 07:37 AM..
 
Old March 3rd, 2011, 07:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I don't think posting the question again is going to get you anywhere.

I don't know the answer to your question because I'm not sure what the question is.

If you just want to write "2" when you see the spanname attribute then that is easy

Code:
<xsl:choose>
<xsl:when test="@spanname"><xsl:attribute name="colspan">2</xsl:attribute></xsl:when>
<xsl:otherwise><xsl:attribute name="colspan">0</xsl:attribute></xsl:otherwise>
</xsl:choose>
Otherwise you need to explain to us the relationship between your input XML, and what you actually want to output.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 3rd, 2011, 08:02 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default

sorry for asking again.

In xml like<tgroup cols="4" frame="all" rowsep="1" colsep="1">
<colspec colnum="1" colname="col1" colwidth="25*" align="left"/>
<colspec colnum="2" colname="col2" colwidth="25*" align="left"/>
<colspec colnum="3" colname="col3" colwidth="25*" align="left"/>
<colspec colnum="4" colname="col4" colwidth="25*" align="left"/>
<spanspec namest="col1" nameend="col2" spanname="sp1"/>
<thead valign="middle">
<row><entry align="center" spanname="sp1">. I want in html like<td align="center" colspan="2">

See the red color used for how many column (start and end) to merge colspan. Green color used for which column you apply colspan.

Kindly suggest for this.
Regards,
Rockbal
 
Old March 3rd, 2011, 09:46 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

OK, here's some bits and pieces that may help, but its not a complete solution.

Firstly you'll have some kind of template for your <entry> element. The key here is to make sure to process the attributes.
Code:
<xsl:template match="row/entry">
<td>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="*"/>
</td>
</xsl:template>
The some simple templates to handle other attributes:
Code:
<xsl:template match="entry/@*"><xsl:copy-of select="."/></xsl:template>
The a special template to handle spanname. You look up the spanspec, and then the two colspec elements, then subtract the two colnum values and add 1.
Code:
<xsl:template match="@spanname">
<xsl:variable name="spec" select="//spanspec[@spanname=current()]"/>
<xsl:variable name="col1" select="//colspec[@colname=$spec/@namest]"/>
<xsl:variable name="col2" select="//colspec[@colname=$spec/@nameend]"/>

<xsl:attribute name="colspan">
<xsl:value-of select="$col2/@colnum - $col1/@colnum + 1"/>
</xsl:attribute>
</xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 4th, 2011, 06:22 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi samjudson,

I really thank you for your reply. i got colsapn, but i need exact colspan. kindly referer the below link and xml coding.
URL: Colspan-getting- my Excepting output html
URL: Colsapn-0notgetting- my current output
URL: input xml file.

http://www.4shared.com/photo/_o2-X-M...n-getting.html
http://www.4shared.com/photo/KhccTXN...otgetting.html
http://www.4shared.com/photo/tB6pSpBZ/xmltag.html
Herewith i have pasted input xml file.
Code:
<table>
<tgroup cols="4" frame="all" rowsep="1" colsep="1">
<colspec colnum="1" colname="col1" colwidth="25*" align="left"/>
<colspec colnum="2" colname="col2" colwidth="25*" align="left"/>
<colspec colnum="3" colname="col3" colwidth="25*" align="left"/>
<colspec colnum="4" colname="col4" colwidth="25*" align="left"/>
<spanspec namest="col1" nameend="col2" spanname="sp1"/>
<thead valign="middle">
<row>
<entry align="center" spanname="sp1"><text>NBCU Ownership Interests</text></entry>
<entry align="center"><text>Ownership<line.break/>Interest (Full,<line.break/>Majority, Half,<line.break/>Minority)</text></entry>
<entry align="center"><text>Contribute to<line.break/>Joint Venture?</text></entry>
</row>
</thead>
<tbody valign="top">
<row>
<entry morerows="3"><text><emph face="B">Attributable broadcast<line.break/>television stations</emph></text></entry>
<entry><text>WNEU, Merrimack, NH</text></entry>
<entry><text>Full</text></entry>
<entry><text>Yes</text></entry>
</row>
<row>
<entry><text>WWDP, Norwell, MA</text></entry>
<entry><text>Minority</text></entry>
<entry><text>Yes</text></entry>
</row>
<row>
<entry><text>WMAQ-TV, Chicago, IL</text></entry>
<entry><text>Full</text></entry>
<entry><text>Yes</text></entry>
</row>
<row>
<entry><text>WSNS-TV, Chicago, IL</text></entry>
<entry><text>Full</text></entry>
<entry><text>Yes</text></entry>
</row>
</tbody>
</table>

Kindly give solution for us.
 
Old March 4th, 2011, 07:48 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What does your XSLT look like? It looks like you aren't outputting the colspan attribute at all, but seeing as you've posted links to pictures of your web page I don't know what your actual output looks like.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 4th, 2011, 08:31 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
see the below link i excepting output.
http://www.4shared.com/photo/_o2-X-M...n-getting.html

how to apply in xsl for colspan?
i already posted xml file for you.

Kindly suggest to us.

Regards,
Rockbal
 
Old March 4th, 2011, 10:02 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Please, no more screenshots. They are no use to me or anyone else.

We need to see the XML (or HTML) that your script is outputting, what you want it be, and what your XSLT looks like (i.e. the actual file, not some screenshot).

I suspect the error is in your XSLT, but you aren't showing us that, so I really can't help you any further.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 5th, 2011, 02:21 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi samjudson,

I really appreciate for your response. I have to posted xml, xslt and html file i.e. (the html files are posted. One for current output and another one is required output html file. The current output file is converting creating my xsl and required html file is I excepting output). I posted all files are below link.

http://www.4shared.com/file/5SMwRemd...able-HTML.html
http://www.4shared.com/document/QGd22_Z1/Table.html
http://www.4shared.com/document/8TNN...nt_output.html
http://www.4shared.com/document/OxvD...ed_output.html

Kindly suggest to us.

Regards,
Rockbal
 
Old March 5th, 2011, 04:20 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The first link doesn't work. I couldn't be bothered to try the others.

Please embed the XSLT into your post using the [ code ] and [ /code ] tags.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling the gaps of rowspan/colspan sources maikm XSLT 3 August 27th, 2008 03:36 AM
Algorithmic problem transformin table with colspan fmilano XSLT 1 June 18th, 2007 02:29 PM





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