[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hi,
That is easy with XSLT 2.0, see below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="coordinate">
<FullCoordinates datum="WGS84">
<xsl:for-each select="tokenize(normalize-space(.), ' ')">
<xsl:variable name="values" select="tokenize(., ',')"/>
<Point longitude="{$values[1]}" latitude="{$values[2]}">
<xsl:if test="$values[3]"><xsl:attribute name="ht_above_geoid" select="$values[3]"/></xsl:if>
</Point>
</xsl:for-each>
</FullCoordinates>
</xsl:template>
</xsl:stylesheet>
on
gives
Ken Starks wrote:
Re: [xsl] Help needed with converting to (patterned) Element content to sub-elements only
Subject: Re: [xsl] Help needed with converting to (patterned) Element content to sub-elements only From: George Cristian Bina <george@xxxxxxxxxxxxx> Date: Sun, 25 Jan 2009 02:59:09 +0200 |
Hi,
That is easy with XSLT 2.0, see below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="coordinate">
<FullCoordinates datum="WGS84">
<xsl:for-each select="tokenize(normalize-space(.), ' ')">
<xsl:variable name="values" select="tokenize(., ',')"/>
<Point longitude="{$values[1]}" latitude="{$values[2]}">
<xsl:if test="$values[3]"><xsl:attribute name="ht_above_geoid" select="$values[3]"/></xsl:if>
</Point>
</xsl:for-each>
</FullCoordinates>
</xsl:template>
</xsl:stylesheet>
on
<coordinate> aaa,bbb,ccc ddd,eee,fff ggg,hhh jjj,kkk,lll </coordinate>
gives
<?xml version="1.0" encoding="UTF-8"?> <FullCoordinates datum="WGS84"> <Point longitude="aaa" latitude="bbb" ht_above_geoid="ccc"/> <Point longitude="ddd" latitude="eee" ht_above_geoid="fff"/> <Point longitude="ggg" latitude="hhh"/> <Point longitude="jjj" latitude="kkk" ht_above_geoid="lll"/> </FullCoordinates>
Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com
Ken Starks wrote:
Hi,
I would really appreciate advice on the following task. My present version uses python,
but I would like to use XSLT.
The input file includes <coordinate> elements of the form <coordinate> aaa,bbb,ccc ddd,eee,fff ggg,hhh jjj,kkk,lll </coordinate>
of which the content, when left and right stripped, is a whitespace-separated sequence of points; each point being a comma-separated sequence of either two or three numbers.
All <coordinate> elements are to be replaced, in the output file, by elements of the form:
<FullCoordinates datum="WGS84" > <Point longitude="aaa" latitude="bbb" ht_above_geoid="ccc"> <Point longitude="ddd" latitude="eee" ht_above_geoid="fff"> <Point longitude="ggg" latitude="hhh"> <Point longitude="jjj" latitude="kkk" ht_above_geoid="lll"> </FullCoordinates>
Please note there is no 'height-above-geoid' attribute in the third <Point>.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Help needed with converting t, Ken Starks | Thread | Re: [xsl] Help needed with converti, Ken Starks |
RE: [xsl] Avoid xmlns (namespace), Michael Kay | Date | [xsl] saxon9-ant.jar and <xmlcatalo, Stefan Krause |
Month |
Keywords