Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2006, 06:29 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert <br> in a table with this xml/xsl?

I have an XML with a template <br></br> which I would like to convert into an html linebreak (<br>), so that the benefittext shown in the xml below is seperated by a linebreak each time the template <br></br> occurs. The template can be manipulated by code before the xml is written, so if you suggest I rewrite the xml with regards to this template then that is no problem.

My xml:

<?xml version='1.0'?><?xml-stylesheet type="text/xsl" href="Css/exampleA.xsl"?>
<NewDataSet>
  <Table>
    <BenefitText>- 10 % discount on sightseeing by bus or boat in London<br></br>
- 10 % discount on sightseeing by bus or boat in Stockholm<br></br>
- 10 % discount on sightseeing by bus or boat in Helsinki<br></br>
- 10 % discount on sightseeing by bus or boat in Copenhagen</BenefitText>
    <BenefitCompanyName>Travels Inc.</BenefitCompanyName>
    <MembershipCompanyName>Happy Memberships</MembershipCompanyName>
    <Categories>Services</Categories>
  </Table>
</NewDataSet>

My xsl:

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

  <xsl:template match="/">
    <html>
      <body>
        <CENTER>
          <H1>Membershipbenefits</H1>
        </CENTER>
        </HR>
        <table border="1" bgcolor="white">
          <tr>
            <th>Membership</th>
            <th>Company</th>
            <th>Benefit</th>
            <th>Category</th>
          </tr>
          <xsl:for-each select="NewDataSet/Table">
            <tr>
              <td>
                <xsl:value-of select="MembershipCompanyName"/>
              </td>
              <td>
                <xsl:value-of select="BenefitCompanyName"/>
              </td>
              <td>
                <xsl:value-of select="BenefitText"/>
        <br>
        <xsl:value-of select="//br"/>
        </br>
              </td>
              <td>
                <xsl:value-of select="Categories"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>


</xsl:stylesheet>

Reply With Quote
  #2 (permalink)  
Old September 22nd, 2006, 07:01 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is what template rules are for.

  <xsl:template match="/">
    <html>
      <body>
        <CENTER>
          <H1>Membershipbenefits</H1>
        </CENTER>
        </HR>
        <table border="1" bgcolor="white">
          <tr>
            <th>Membership</th>
            <th>Company</th>
            <th>Benefit</th>
            <th>Category</th>
          </tr>
          <xsl:apply-templates select="NewDataSet/Table"/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Table">
            <tr>
              <td>
                <xsl:apply-templates select="MembershipCompanyName"/>
              </td>
              <td>
                <xsl:apply-templates select="BenefitCompanyName"/>
              </td>
              <td>
                <xsl:apply-templates select="BenefitText"/>
              </td>
              <td>
                <xsl:apply-templates select="Categories"/>
              </td>
            </tr>
   </xsl:template>

   <xsl:template match="br">
      <br/>
   </xsl:template>

You don't need any other rules: the defaults do the right thing.

Also remember to use <xsl:output method="html"/> to get the <br> element formatted correctly for HTML output.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace "<enter>" with "<br>" Varg_88 Classic ASP Basics 5 February 14th, 2011 12:33 PM
embedded <xsl:element> into <xsl:with-param> petergoodman XSLT 2 July 9th, 2008 06:36 AM
<br/> becomes <br></br> Kabe XSLT 1 July 6th, 2007 07:42 AM
to append <br> in XSLT dharus XSLT 4 August 1st, 2006 09:52 AM
Replace vbcrlf with <br> using C# kgriffin ASP.NET 1.0 and 1.1 Basics 2 May 4th, 2005 09:29 AM



All times are GMT -4. The time now is 01:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.