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 June 3rd, 2004, 04:23 AM
Rajani_vanamala Rajani_vanamala is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Rajani_vanamala User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 21 sec
Reputation Power: 0
Thumbs up <xsl:attribute> element

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.

Reply With Quote
  #2  
Old June 3rd, 2004, 04:48 AM
nihaarika2002 nihaarika2002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 49 nihaarika2002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
xml attribute

hi rajani
i think u have to use xsl:variable instead of attribute

attribute is for - xml
xsl:variable or xslarameter for - xsl
may 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

Reply With Quote
  #3  
Old June 3rd, 2004, 05:19 AM
Rajani_vanamala Rajani_vanamala is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Rajani_vanamala User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 21 sec
Reputation Power: 0
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 .

Reply With Quote
  #4  
Old June 3rd, 2004, 05:29 AM
nihaarika2002 nihaarika2002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 49 nihaarika2002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > <xsl:attribute> element


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 4 hosted by Hostway