?
Solved

XSLT transformation help (font, paragraph spacing)

Posted on 2009-02-21
5
Medium Priority
?
469 Views
Last Modified: 2013-11-18
I've got an XSLT file transforming an XML control (ASP.NET) on my website.  The problem is that my transformation isn't showing me the text the way I want it displayed.  I'll attach a sample of my XML file and an XSLT file that I'm working on.  I've got a screenshot from photoshop about the way I want it to look and I'll attach that too.  Can somebody point out in my transformation where I went wrong? Thanks
<?xml version="1.0" encoding="utf-8"?>
<Message>
  <Message>
    <title>First Message</title>
    <subtitle>First</subtitle>
    <date>2/4/2009</date>
    <messagetext>Hello World</messagetext>
  </Message>
  <Message>
    <title>Hey</title>
    <subtitle>Make more sales</subtitle>
    <date>2/12/2009</date>
    <messagetext>Sending message</messagetext>
  </Message>
  <Message>
    <title>Hey</title>
    <subtitle>none</subtitle>
    <date>2/16/2009</date>
    <messagetext>Testing out the spacing for the messages, supposed to only retrieve three of the most current messages</messagetext>
  </Message>
  <Message>
 
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:template match="Message[Message]">
    <xsl:variable name="no-of-mess">
      <xsl:value-of select="count(Message)"/>
    </xsl:variable>
    <html>
      <body>
        
        
        <table border="0" style="height:50px">
          
          <xsl:apply-templates select="Message[position() > ($no-of-mess - 3) ]"/>
                    </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="Message[parent::Message]">
    <tr>
      <td style="color:red; font-weight:bold">
        
        <xsl:value-of select="date"/>
        <br/>
      </td>
      <td style ="font-weight:bold">        <xsl:value-of select="messagetext"/>
        <br/>
      
      </td>
    </tr>
    <br/>
    <br/>
  </xsl:template>
</xsl:stylesheet>

Open in new window

screenshot007.jpg
0
Comment
Question by:JeffEae
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Ken Fayal
ID: 23701118
Try this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:template match="Message[Message]">
    <xsl:variable name="no-of-mess">
      <xsl:value-of select="count(Message)"/>
    </xsl:variable>
    <html>
      <body>
        
        
        <table border="0" style="height:50px">
          
          <xsl:apply-templates select="Message[position() > ($no-of-mess - 3) ]"/>
                    </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="Message[parent::Message]">
    <tr>
      <td style="color:red; font-weight:bold">
        
        <xsl:value-of select="date"/>
        <br/>
      </td>
      <td style ="font-weight:bold">        <xsl:value-of select="messagetext"/>
        <br/>
      
      </td>
    </tr>
    <br/>
    <br/>
  </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:JeffEae
ID: 23701152
I'll show you what came up.  The date and messagetext are still on the same line.  That <br/> seems to not work to get the date on its own line and then its still not skipping lines for the next message.  
screenshot008.jpg
0
 
LVL 9

Accepted Solution

by:
Ken Fayal earned 2000 total points
ID: 23701165
Sorry.. the paste I did didn't work..

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:template match="Message[Message]">
    <xsl:variable name="no-of-mess">
      <xsl:value-of select="count(Message)"/>
    </xsl:variable>
    <html>
      <body>
        
        
        <table border="0" style="height:50px">
          
          <xsl:apply-templates select="Message[position() > ($no-of-mess - 3) ]"/>
                    </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="Message[parent::Message]">
    <tr>
      <td style="color:red; font-weight:bold">
        
        <xsl:value-of select="date"/>
        
      </td>
      </tr>
      <tr>
 
      <td style ="font-weight:bold">        <xsl:value-of select="messagetext"/>
        <br/>
      
      </td>
    </tr>
    <br/>
    <br/>
  </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:JeffEae
ID: 23701341
I added another <br> under
<td style ="font-weight:bold">        <xsl:value-of select="messagetext"/>
        <br/>
       <br/>

It has my desired output now.  You are the man!
0
 
LVL 9

Expert Comment

by:Ken Fayal
ID: 23701361
Glad to help.  Thanks for the points!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question