|
next
|
 Subject: Extracting specific comma separated data Author: Mark Kieffer Date: 24 Jul 2007 01:31 PM
|
Hi,
I have an xml with comma separated data, but I want to extract only specific values from these data. Here is the part of xml I am interested in:
<dataset xmlns="http://datafed.net/xs/Catalog">
<LatLonTimeCube>
<dimensions>
<parameter_dim dim_type="parameter">
<granules>
param_abbr, param_name, param_unit
CO, CO Total, gm-2s-1
CO2, CO2 Total, gm-2s-1
NO, NO Total, g.m-2s-1
NO2, NO2 Total, gm-2s-1
SO2, SO2 Total, gm-2s-1
</granules>
</parameter_dim>
</dimensions>
</LatLonTimeCube>
</dataset>
I would like the output to be
Parameters=CO, CO2, NO, NO2, SO2
I looked around and could only find information on extracting all the values in order.
Thanks,
Mark
|
top
|
 Subject: Extracting specific comma separated data Author: Mark Kieffer Date: 25 Jul 2007 01:39 PM
|
I think I am stuck in XSLT 1.0 for now. So I am working on the recursive function that you mentioned. I found a good starting point after a few searches, but I am still having trouble skipping the values in between the values I want. So far I have
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="granules">
<xsl:variable name="dataString" select="text()"/>
<xsl:call-template name="commaSplit">
<xsl:with-param name="dataString" select="$dataString"/>
<xsl:with-param name="position" select="1"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="commaSplit">
<xsl:param name="dataString"/>
<xsl:param name="position"/>
<xsl:choose>
<xsl:when test="contains($dataString,'param_abbr, param_name, param_unit')">
<!-- Select the first value to process -->
<xsl:call-template name="doWhatever">
<xsl:with-param name="doWith"
select="substring-before($dataString,'param_abbr, param_name, param_unit')"/>
<xsl:with-param name="position" select="$position"/>
</xsl:call-template>
<!-- Recurse with remainder of string -->
<xsl:call-template name="commaSplit">
<xsl:with-param name="dataString"
select="substring-after($dataString,'param_abbr, param_name, param_unit')"/>
<xsl:with-param name="position" select="$position + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- This is the last value so we don't recurse -->
<xsl:call-template name="doWhatever">
<xsl:with-param name="doWith" select="$dataString"/>
<xsl:with-param name="position" select="$position"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Process of individual value here -->
<xsl:template name="doWhatever">
<xsl:param name="doWith"/>
<xsl:param name="position"/>
<outputValueInElementWithABigLongName position="{$position}">
<xsl:value-of select="$doWith"/>
</outputValueInElementWithABigLongName>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
This gets rid of the first 3 values, but I cannot figure anything else out.
|
|
|
|