|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
The following are the XML and the correcsponding XSL scripts. I learnt that <xsl:attribute> element can be used to add an attribute in the result tree. Where as, while executing the following XML program, a blank screen is being displayed. The expected output is the list of all ARTIST with PRICE >10 and attribute source='1988'. I presume that with the following XSL code the attribute source is added to CD tag. The XML script is: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="addattributetocatlog.xsl"?> <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>10.90</PRICE> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>RCA</COMPANY> <PRICE>10.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG> The XSL script is: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <xsl:for-each select="CATALOG/CD"> <xsl:attribute name="source"> <xsl:value-of select="YEAR"/>##<br/> </xsl:attribute> </xsl:for-each> <xsl:for-each select="CATALOG/CD[@source='1988']"> <xsl:if test="PRICE > 10"> <xsl:value-of select="ARTIST"/><br /> </xsl:if> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> Any suggestions welcome. Thanks in advance. |
|
#2
|
|||
|
|||
|
xml attribute
hi rajani
i think u have to use xsl:variable instead of attribute attribute is for - xml xsl:variable or xsl arameter for - xslmay be i m wrong..but this is what i know -- i slightly modified ur code - i think this is the overall effect u r looking for... --------------------- <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <!-- <xsl:for-each select="CATALOG/CD"> <xsl:attribute name="source"> <xsl:value-of select="YEAR"/>##<br/> </xsl:attribute> </xsl:for-each> <xsl:for-each select="CATALOG/CD[@source='1988']"> <xsl:if test="PRICE > 10"> <xsl:value-of select="ARTIST"/><br /> </xsl:if> </xsl:for-each> --> <xsl:for-each select="//CATALOG/CD[PRICE > 10]"> <xsl:variable name="source" select="YEAR"/> <!--<xsl:value-of select="$source"/>--> <xsl:if test="$source = '1988'"> <xsl:value-of select="ARTIST"/><br /> </xsl:if> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> --------------------- regards niha |
|
#3
|
|||
|
|||
|
Hi Niha,
I appreciate ur response, and it is workin fine. However, what am i trying to do is to add an attribute named "source" to element "CD" in the given xml code. That is, I am expecting the parser to transform the code something as follows: <CATALOG> <CD source="1985"> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> and so on. Actually here I am experimenting <xsl:attribute> element, rather than concentrating on the result. The information regarding this attribute is obtained from the following link: URL Any other suggestions greatly appreciated. Thank you, Niha . |
|
#4
|
|||
|
|||
|
thank u
yah i can c now what u mean...sorry i misunderstood it..
if u find any solution pls let me know also . mean while i also try to dig here with regards niha |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > <xsl:attribute> element |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|