Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:29:37+00:00 2026-06-11T17:29:37+00:00

I have a space-separated list of coordinate tuples, with arbitrarily many tuples. Each tuple

  • 0

I have a space-separated list of coordinate tuples, with arbitrarily many tuples. Each tuple consists of a space-separated list of 2-dimensional coordinates. E.g. “1.1 2.8 1.2 2.9” represents a line from POINT(1.1 2.8) to POINT(1.2 2.9). I need this to instead be “1.1,2.8 1.2,2.9”. How would I use XSLT to perform the replacement of space-to-comma between pairs of numbers? I have the “string(gml:LinearRing/gml:posList)”.

This is being used on a Java Web Service that spits out GML 3.1.1 features with geometries. The service supports optional KML output, by using XSLT to transform the GML document into a KML document (at least, the chunks deemed “important”). I am locked into XSLT 1.0, so regex from XSLT 2.0 is not an option.

I am aware that GML uses lat/lon while KML uses lon/lat. That’s being handled before XSLT, though it would be nice to have that also done with XSLT.


Thank you for your solution, Dimitre. I modified it a little to fit my needs, so I’ll include that here in case it helps anyone else. It performs recursion through the coordinate list, assuming 2-dimensional tuples.

This performs two functions: axis swapping (lat/lon for lon/lat, per GML and KML specs) and changing the coordinate separator within each tuple from space ‘ ‘ to comma ‘,’.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gml="http://www.opengis.net/gml" exclude-result-prefixes="gml">
   <xsl:output method="xml" encoding="UTF-8" indent="yes" />

   <!-- other portions omitted -->

   <xsl:template match="gml:pos">
      <xsl:call-template name="coordinateSequence">
         <xsl:with-param name="coords" select="normalize-space(string(.))" />
      </xsl:call-template>
   </xsl:template>

   <xsl:template match="gml:posList">
      <xsl:call-template name="coordinateSequence">
         <xsl:with-param name="coords" select="normalize-space(string(.))" />
      </xsl:call-template>
   </xsl:template>

   <xsl:template name="coordinateSequence">
      <xsl:param name="coords" />
      <xsl:if test="string-length($coords) > 0">
         <xsl:variable name="lat" select="substring-before($coords, ' ')" />
         <xsl:variable name="lon">
            <xsl:value-of select="substring-before(substring-after($coords, ' '), ' ')" />
            <xsl:if test="string-length(substring-before(substring-after($coords, ' '), ' ')) = 0">
               <xsl:value-of select="substring-after($coords, ' ')" />
            </xsl:if>
         </xsl:variable>
         <xsl:variable name="remainder" select="substring-after(substring-after($coords, ' '), ' ')" />

         <xsl:value-of select="concat($lon, ',', $lat)" />
         <xsl:if test="string-length($remainder) > 0">
            <xsl:value-of select="' '" />
            <xsl:call-template name="coordinateSequence">
               <xsl:with-param name="coords" select="$remainder" />
            </xsl:call-template>
         </xsl:if>
      </xsl:if>
   </xsl:template>

</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:29:39+00:00Added an answer on June 11, 2026 at 5:29 pm

    This transformation (also shows the intermediary steps):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"/>
    
     <xsl:template match="/*">
      <xsl:variable name="vNorm" select="normalize-space()"/>
      <xsl:variable name="vP1" select=
      "concat(substring-before(., ' '), ',',
              substring-before(substring-after($vNorm, ' '),' ')
              )"/>
    
      <xsl:variable name="vPart2" select="substring-after(substring-after($vNorm,' '),' ')"/>
    
      <xsl:variable name="vP2" select=
      "concat(substring-before($vPart2, ' '), ',',
              substring-after($vPart2, ' ')
              )"/>
    
    
      <xsl:value-of select="$vP1"/>
    ==========
      <xsl:value-of select="$vP2"/>
    ==========
      <xsl:value-of select="concat($vP1, ' ', $vP2)"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <t>1.1 2.8 1.2 2.9</t>
    

    produces the wanted, correct result (the last line):

    1.1,2.8
    ==========
      1.2,2.9
    ==========
      1.1,2.8 1.2,2.9
    

    For convenience, this code can be placed in to a named template to be called for each wanted Line:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"/>
    
     <xsl:template match="/*">
      <xsl:call-template name="convertLine"/>
     </xsl:template>
    
     <xsl:template name="convertLine">
      <xsl:param name="pStr" select="."/>
    
      <xsl:variable name="vNorm" select="normalize-space($pStr)"/>
      <xsl:variable name="vP1" select=
      "concat(substring-before($pStr, ' '), ',',
              substring-before(substring-after($vNorm, ' '),' ')
              )"/>
    
      <xsl:variable name="vPart2" select="substring-after(substring-after($vNorm,' '),' ')"/>
    
      <xsl:variable name="vP2" select=
      "concat(substring-before($vPart2, ' '), ',',
              substring-after($vPart2, ' ')
              )"/>
    
    
      <xsl:value-of select="concat($vP1, ' ', $vP2)"/>
     </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that represents a list of tags separated by space. It
I have a products table with a column that contains a space separated list
I would like to have some space between the same line.. I know there
i have two points in 3D space which have X-coordinates with different signum. so
How would I match a space separated list of words followed by whitespace and
I have a large file of names and values on a single line separated
I have imported a file containing 8 columns, each column separated by '\t' ,
I have a data stored in a xml column and need a comma-separated list
I have a 384MB text file with 50 million lines. Each line contains 2
I have a string of values separated by a space that I return to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.