XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 5th, 2004, 06:09 AM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
starts-with XSL function - HELP!!

I have an XML file which looks like this:

<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
.
.
.
</catalog>

My xslt looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="1" cellpadding="0" cellspacing="0" width="50%">
<tr>
<td class="heading" colspan="2">Leila's music box</td>
</tr><tr bgcolor="#9acd32">
<td class="textSmall">Artist</td>
<td class="textSmall">Title</td>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<tr>

<xsl:if test = "catalog/cd[starts-with(artist, 'a')]">
<td bgcolor="#B0F3A1">
<xsl:value-of select="artist"/>
</td>
<td bgcolor="#B0F3A1">
<xsl:value-of select="title"/>
</td>
</xsl:if>

<xsl:if test = "catalog/cd[starts-with(artist, 'b')]">
<td bgcolor="#F3A1A5">
<xsl:value-of select="artist"/>
</td>
<td bgcolor="#F3A1A5">
<xsl:value-of select="title"/>
</td>
</xsl:if>
.
.
.

</tr>
</xsl:for-each>

</table>
</xsl:template>

</xsl:stylesheet>

I am attempting to use the <xsl:if ...> statement to check which letter the artist name begins with, and depending on that, I change the background colour of the <td> tag.

But this line <xsl:if test = "catalog/cd[starts-with(artist, 'b')]"> is not working. What am I doing wrong???

Any help would me most appreciated!

Leila

Reply With Quote
  #2  
Old July 5th, 2004, 06:58 AM
prajitha prajitha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 prajitha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile starts-with XSL function - HELP!!

Instead of the line <xsl:if test = "catalog/cd[starts-with(artist, 'a')]">, Give <xsl:if test = "starts-with(artist, 'A')">.

In the For Statement, you have mentioned catalogue/cd. So already you are in cd subtree. Next you have to mention artist element. And remember xml is case sensitive. So use capital "A" and "B"

Reply With Quote
  #3  
Old July 5th, 2004, 07:02 AM
prajitha prajitha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 prajitha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile tarts-with XSL function - HELP!!

Instead of the line <xsl:if test = "catalog/cd[starts-with(artist, 'a')]">, Give <xsl:if test = "starts-with(artist, 'A')">.

In the For Statement, you have mentioned catalogue/cd. So already you are in cd subtree. Next you have to mention artist element. And remember xml is case sensitive. So use capital A and B

Reply With Quote
  #4  
Old July 5th, 2004, 07:57 AM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
thanks prajitha!

finally got it working!

much appreciated,
leila

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > starts-with XSL function - HELP!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT