• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

XSLT transformation help (font, paragraph spacing)

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
JeffEae
Asked:
JeffEae
  • 3
  • 2
1 Solution
 
Ken FayalCTOCommented:
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
 
JeffEaeAuthor Commented:
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
 
Ken FayalCTOCommented:
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
 
JeffEaeAuthor Commented:
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
 
Ken FayalCTOCommented:
Glad to help.  Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now