XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Mark KiefferSubject: Extracting specific comma separated data
Author: Mark Kieffer
Date: 24 Jul 2007 01:31 PM
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">
<parameter_dim dim_type="parameter">
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

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.


Minollo I.Subject: Extracting specific comma separated data
Author: Minollo I.
Date: 24 Jul 2007 04:59 PM
I think yout best option is to use XSLT 2 and the tokenize() function (http://www.w3.org/TR/xpath-functions/#func-tokenize)

If the parsing/conversion of the embedded text gets too complicated, you may want to consider extracting it from the XML and parsing it using XML Converters, for example (http://www.xmlconverters.com).

Jan VerhoekSubject: Extracting specific comma separated data
Author: Jan Verhoek
Date: 24 Jul 2007 05:03 PM
With XSLT and the Tokenize function it could look like:

<xsl:template match="granules">
<xsl:variable name="gran" select="tokenize(., '\n')[position()>1]"/>

<xsl:if test="$gran[1]">
<xsl:text>Parameters: </xsl:text>
<xsl:for-each select="$gran">
<xsl:value-of select="tokenize(., ',')[1]"/>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>


If you're stuck to XSLT 1.0 try substring within a recursive function!

Mark KiefferSubject: 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"

<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:template name="commaSplit">
<xsl:param name="dataString"/>
<xsl:param name="position"/>
<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"/>
<!-- 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"/>
<!-- 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"/>

<!-- 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"/>

<xsl:template match="*">


This gets rid of the first 3 values, but I cannot figure anything else out.

Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.