Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving values from XML file 1

Status
Not open for further replies.

TomKane

Programmer
Jul 24, 2001
1,018
AU
Hi,

I'm attempting to get at certain values from an XML file. I'm not getting any values back and certainly would certainly apprecitate some feedback. The XML structure is as below:

<?xml version="1.0"?>

<output xmlns:ac=" <ado symbol="C0.1000005493" description="EURKWD Spot" template="C0_I_T006_LSA">
<static>
<rms_code time-stamp="-2208988800000" status="1">
<string>EURKWD</string>
</rms_code>
<ccy time-stamp="1151675243000" status="1">
<enumeration>KWD</enumeration>
</ccy>
<xccy time-stamp="-2208988800000" status="1">
<enumeration>EUR</enumeration>
</xccy>
</static>
<time-series id="GOLDEN_COPY">
<record>
<date status="63">
<integer>20061121</integer>
</date>
<time status="63">
<integer>235959</integer>
</time>
<rate status="1">
<double>0.37088944199999996</double>
</rate>
</record>
</time-series>
</ado>

The value I'm trying to get is the double element. The XSL file I'm using is as below:

<?xml version="1.0"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "<xsl:eek:utput method="text" encoding="utf-8"/>
<xsl:template match="node()">
<xsl:if test="name()='ado'">
<xsl:text>&#x0d;&#x0a;</xsl:text>
</xsl:if>
<xsl:for-each select="output/ado">
<xsl:value-of select="time-series/record/rate/double"/>
<xsl:text>&#x09;</xsl:text>
</xsl:for-each>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>

Unfortunately I'm not getting anything back. I would be very grateful for any and all advice.

Thanks and regards,
Tom
 
You may have a good reason to script like that maybe to integrate into other fragment, I suppose. This is a way to retrieve the listing using as many existing lines for better transition. This suppose multiple time-series inside an ado. But if it is actually multiple time inside time-series, then it should be modified to reflect this.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "<xsl:eek:utput method="text" encoding="utf-8"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="ado">
<xsl:text>start listing the double inside an ado tag &#x0d;&#x0a;</xsl:text>
<xsl:for-each select="time-series">
<xsl:value-of select="record/rate/double"/>
<xsl:text>&#x09;</xsl:text>
</xsl:for-each>
<!-- <xsl:apply-templates /> --><!-- no need of this -->
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Hi tsuji,

Many thanks for getting back to me so fast. There are multiple ado but onely one time-series per ado. Does that make sense?

Thanks,
Tom

 
In that case, there is no more reason for xsl:for-each inside the template matching ado.

This is one way.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "<xsl:eek:utput method="text" encoding="utf-8"/>
<xsl:template match="/">
<xsl:text>start listing the double inside each ado tag &#x0d;&#x0a;</xsl:text>
<xsl:apply-templates select="output/ado" />
</xsl:template>
<xsl:template match="ado">
<xsl:value-of select="time-series/record/rate/double"/>
<xsl:text>&#x09;</xsl:text>
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Hi tsuji,

That's really great!! What I ended up doing is this:

<?xml version="1.0"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "<xsl:eek:utput method="text" encoding="utf-8"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="output">
<xsl:for-each select="ado">
<xsl:value-of select="static/xccy/enumeration"/>
<xsl:text>&#x09;</xsl:text>
<xsl:value-of select="static/ccy/enumeration"/>
<xsl:text>&#x09;</xsl:text>
<xsl:value-of select="time-series/record/rate/double"/>
<xsl:text>&#x0d;&#x0a;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

As I want to get a value out of the static section as well.

Thanks for all your help with this. It's much appreciated.

Regards,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top