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 April 15th, 2009, 10:40 AM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default Need to add a line after ever row of data displayed

I have the following xsl which writes two columns of data in a row....


i.e.

Location1 Location2
Address Address
tel tel
fax fax

Code:
<tr valign="top" width="521">
           <td align="top" valign="top">
                    <xsl:for-each select="/Properties/Data/Datum/DCR/contactus/contenttype [position() mod 2 = 1]">
                    <xsl:variable name="varLocation" select="location/location"/>
                    <xsl:if test="$varLocation != ''">
                      <span class="MarkitSubHeading">
                        <a name="{location/location}">
                          <xsl:value-of select="location/location" disable-output-escaping="yes"/>
                        </a>
                      </span><br/>
                      <span class="MarkitSubSubHeading">Address</span><br/> 
                      <span class="MarkitBodyText">
                        <xsl:value-of select="location/address" disable-output-escaping="yes"/><br/>
                        <b>Tel</b>:&nbsp;<xsl:value-of select="location/tel" disable-output-escaping="yes"/><br/>
                        <b>Fax</b>:&nbsp;<xsl:value-of select="location/fax" disable-output-escaping="yes"/><br/><br/>
                      </span>
                    </xsl:if>
                  </xsl:for-each>
                </td>
                <td align="top" valign="top">
                    <xsl:for-each select="/Properties/Data/Datum/DCR/contactus/contenttype [position() mod 2 = 0]">
                    <xsl:variable name="varLocation" select="location/location"/>
                    <xsl:if test="$varLocation != ''">
                    <span class="MarkitSubHeading">
                      <a name="{location/location}">
                      <b><xsl:value-of select="location/location" disable-output-escaping="yes"/></b>
                      </a>
                    </span>
                    <br/>
                    <span class="MarkitSubSubHeading">Address</span><br/>
                    <span class="MarkitBodyText">
                       <xsl:value-of select="location/address" disable-output-escaping="yes"/><br/>
                       <b>Tel</b>:&nbsp;<xsl:value-of select="location/tel" disable-output-escaping="yes"/><br/>
                       <b>Fax</b>:&nbsp;<xsl:value-of select="location/fax" disable-output-escaping="yes"/><br/><br/>
                     </span>
                    </xsl:if> 
                  </xsl:for-each>                
                </td>
         </tr>
I have a requirement to add a vertical line (which spans two columns) after every row of data displayed i.e.


Location1 Location2
Address Address
tel tel
fax fax
__________________________________________________ ________

Location3 Location4
Address Address
tel tel
fax fax
__________________________________________________ ________




Have not been able to figure out how to do this, since depending on the number of records in the xml there could be more than one row of data.

Thanks.
 
Old April 15th, 2009, 10:50 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You seem to transform XML to HTML and create a HTML table in the transformation result so having a vertical line after each row or between two rows is simply a question of finding the right HTML markup and maybe CSS style settings. See http://www.w3.org/TR/html4/struct/tables.html#h-11.3.1, you probably want
Code:
<table rules="rows">
...
</table>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old April 15th, 2009, 10:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, get rid of that disable-output-escaping="yes" nonsense. This is only needed if you want to generate markup by hand or if you want to generate invalid markup. You don't want to do either of these things, I hope.

Secondly, do you know what HTML you want to generate? If not, then don't start thinking about the XSLT coding until you do.

As you've described it, it looks trivial. You've got an instruction to generate a <tr> element, after that you want to generate whatever HTML it is that gives your horizontal rule, e.g. another <tr> element with appropriate attributes.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 15th, 2009, 12:41 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Quote:
Secondly, do you know what HTML you want to generate? If not, then don't start thinking about the XSLT coding until you do.
Thanks Martin.

Basically for each row displayed, I need to add a horizontal line.
 
Old April 15th, 2009, 12:50 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Basically for each row displayed, I need to add a horizontal line.

I wasn't asking what visual appearance you want to achieve. I was asking what HTML you want to generate. There are many ways of producing a horizontal line in HTML (or CSS), for example by setting borders on the cells above, or by producing a row of thin coloured cells, etc etc.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 15th, 2009, 01:13 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks. The html I want to generate is as follows
Code:
<tr>
    <td> Location1 <br/>
            Address 1 <br/>
            telephone 1 <br/>
            Fax 1 <br/>
    </td>
      <td> Location2 <br/>
             Address 2 <br/>
             telephone 2 <br/>
             Fax 2 <br/>
     </td>
   </tr>
 <tr>
       <td>horizontal line image</td>
 </tr>

So for every row (very two columns) add the horizontal line( which is an image I already have). Also, the horizontal line should not be displayed for the last row displayed. Hope this makes my dilemma clearer. - Thanks.
 
Old April 15th, 2009, 01:23 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well now I've looked at your code again and it's generating a table containing a single row, so it's a complete mess. You want something like this:

<table>
<xsl:for-each select="/a/b/c[position() mod 2 = 1]">
<tr>
<td>
<xsl:apply-templates select="." mode="fill-cell"/>
</td>
<td>
<xsl:apply-templates select="following-sibling::*[1]" mode="fill-cell"/>
</td>
</tr>
<xsl:if test="position() &lt; count(/a/b/c) div 2">
<tr>horizontal rule image</tr>
</xsl:if>
</xsl:for-each>
</table>

May need a bit of tweaking to get the arithmetic right, but that's the general structure. The common code for cells could go inline, but it's better to factor it out into a separate template.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
rabs (April 15th, 2009)
 
Old April 15th, 2009, 01:59 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks Martin - with a bit of tweaking, that worked.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a "line-break" in footer tatsuyalam Infopath 0 December 7th, 2007 03:22 AM
How to include a new line after every row --Help srkarthik_82 General .NET 2 January 7th, 2007 09:05 PM
data not being displayed goingmad SQL Server ASP 8 March 27th, 2006 03:36 AM
Manage data row by row in datagrid Dragonist Classic ASP Databases 5 July 29th, 2004 04:17 AM
Line/Row Position jmss66 Classic ASP Databases 7 July 28th, 2003 07:56 PM





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