|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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"> <xsl utput 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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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"> <xsl utput 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"> <xsl aram 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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL, looping, and context |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|