|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
|||
|
|||
|
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" |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
thanks prajitha!
finally got it working! much appreciated, leila |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > starts-with XSL function - HELP!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|