Link to home
Start Free TrialLog in
Avatar of JeffEae
JeffEae

asked on

Change font and skip lines in XSL


Hi, I'm new to XSL transformations so bear with me.  I've got an xsl stylesheet where I'm trying to skip lines after each XML item called 'message'.  I haven't figured out where to put my <br/> tags, and I also want to be able to change the font of my xml element node 'date' to a different font color.  I'm brand new so I appreciate any help
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
 <xsl:output method="xml" indent="yes"/>
     
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
      <table width="500" border="0">
        <xsl:for-each select="Message">
          <tr>
            <td>
              <xsl:value-of select="message" />
            
            </td>
            </tr>
         
          <br/>
        </xsl:for-each>
      </table>
   
       </xsl:template>
</xsl:stylesheet>

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

This can not be very usefull, You generate a table for every element in the tree, and for every attribute.
Can you send in a piece of the source XML please?

You will need to add something like this

  <xsl:template match="message">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    <br />
</xsl:template>
It would be very nice if you would send a small piece of the XML and a small piece of the HTML you expect from it
Avatar of JeffEae
JeffEae

ASKER

Sorry about that.  Here's the XML
<?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>

Open in new window

Do you want this in a table?
What is the HTML you want with this.
If you put it in a table it will come out just fine
Avatar of JeffEae

ASKER

I guess I want each 'Message'  in its own table with red font for the date element and each table to skip a line.  
Try this to start with and see wheither it comes close to what you need.
The predicates in the match attributes are to make distinction between Message elements that have a Message children an dthose that have a Message parent

If you control the XML, change it to using <Messages> as a container instead of <Message>
The current model sucks
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="Message[Message]">
        <html>
            <body>
                <table border="1">
                    <xsl:apply-templates select="Message"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="Message[parent::Message]">
        <tr>
            <td><xsl:value-of select="title"/></td>
            <td><xsl:value-of select="subtitle"/></td>
            <td style="color:blue;"><xsl:value-of select="date"/></td>
            <td><xsl:value-of select="messagetext"/></td>
        </tr>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JeffEae

ASKER

Appreciate your patience and promptness!