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 February 11th, 2004, 11:01 AM
s_c_gardner s_c_gardner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: NYC
Posts: 8 s_c_gardner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
XSL, looping, and context

Gyugh! What I really need to know is whether and how, after you've gone into a for-each loop you can get an attribute of an ancestor element (which isn't the current context).

Examples speak louder than words. . .

XML file (excerpt)
<?xml version="1.0" encoding="UTF-8"?>
<meta_data>
<symbol client_code="04789">
<ratings>
<rating BM_id="15" description="Shr.O/S-Diluted (mm)" client_code="SHARES_OUT">16.596</rating>
<rating BM_id="30" description="Market Cap.($mm)" client_code="MKT_CAP">611.57</rating>
<rating BM_id="34" description="Avg Daily Vol (3 Mo)" client_code="AVG_DAIL_VOL_SH">38346</rating>
<rating BM_id="179" description="Price/Book" client_code="MKT_TO_BOOK">NM</rating>
<rating BM_id="182" description="Yield" client_code="YIELD">NM</rating>
<rating BM_id="185" description="Leverage Ratio" client_code="LEVERAGE_RATIO">NA</rating>
<rating BM_id="211" description="Insider Ownership" client_code="INSIDER_OWN_PCT">10.822</rating>
<rating BM_id="215" description="Moody" client_code="MOODYS_RATING">NA</rating>
<rating BM_id="217" description="S&P" client_code="S_P_RATING">NA</rating>
<rating BM_id="219" description="Long Term Growth Rate (con)" client_code="LNGTRM_GR_RATE_CON">NA</rating>
</ratings>
<financials>
</financials>
</symbol>

XSL file (excerpt)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xslutput method="text" encoding="windows-1252"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="meta_data">
<xsl:for-each select="symbol"><xsl:call-template name="ratings"/></xsl:for-each></xsl:template>
<xsl:template name="ratings"><xsl:for-each select="ratings/rating">
INSERT INTO RCR (TARGET_ID, TARGET_TABLE, TARGET_COL, TARGET_DATE, NEW_VALUE, TIME_STAMP) values ('<xsl:value-of select="@id"/>',<xsl:choose>
<xsl:when test="ratings/rating/@client_code = 'SHARES_OUT'">'SCN',</xsl:when>
<xsl:when test="ratings/rating/@client_code = 'MKT_CAP'">'SCN',</xsl:when>
<xsl:when test="ratings/rating/@client_code = 'AVG_DAIL_VOL_SH'">'SCN',</xsl:when>
. . .

Essentially, I'm trying to get the symbol id into my insert statement. However, once I've gotten into the loop, I can't get at the symbol id anymore, but I need to write it out for each of the ratings/rating elements.

Help/direction appreciated!

Thanks,

sam

Reply With Quote
  #2  
Old February 11th, 2004, 03:30 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Just change the @id to @BM_id

You also may want to remove the ratings/rating/ before the @client_code to get your code to work like I am assuming you want to.

Last edited by MattSidesinger : February 11th, 2004 at 03:35 PM.

Reply With Quote
  #3  
Old February 12th, 2004, 07:38 AM
s_c_gardner s_c_gardner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: NYC
Posts: 8 s_c_gardner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ah, sorry, I shouldn't have used "id" when I mean symbol "client_code" attribute. Actually, it turns out that was contributing quite a bit to my problems. I have eventually solved what I meant to do (retain the client_code while cycling through the lower nodes):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xslutput method="text" encoding="windows-1252"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="meta_data">
<xsl:apply-templates/></xsl:template>
<xsl:template match="symbol">
<xslaram name="sym" select="@client_code"/>
<xsl:for-each select="ratings/rating">
INSERT INTO RCR (TARGET_ID, TARGET_TABLE, TARGET_COL, TARGET_DATE, NEW_VALUE, TIME_STAMP) values ('<xsl:value-of select="$sym"/>',<xsl:choose>
<xsl:when test="@client_code = 'SHARES_OUT'">'SCN',</xsl:when>
<xsl:when test="@client_code = 'MKT_CAP'">'SCN',</xsl:when>
blah, blah, blah. . .

Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL, looping, and context


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 5 hosted by Hostway
Stay green...Green IT