Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2007, 10:44 AM
Authorized User
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Extract coordinates with regex

I have a KML file with polygon coordinates like:

Code:
<coordinates>25.78640267409176,31.97431777211461,0 25.78640267409176,31.97431777211461,0 25.78640267409176,31.97431777211461,0 .... </coordinates>
(number1,number2,0 number1,number2,0 number1,number2,0 ...)

and I would like to extract them in the form of:

Code:
<numbers><number1>...</number1><number2>...</number2></numbers>
for this to happen I need regex and xsl:analyze-string for an XSLT
transformation, but I'm not familiar with regular expressions.

Has anyone used such a method..?

 
Old April 16th, 2007, 10:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I wouldn't use analyze-string for this, I would do something like

<xsl:for-each select="tokenize($in, ' ')">
  <numbers>
    <xsl:for-each select="tokenize(., ',')">
      <xsl:element name="number{position()}">
        <xsl:value-of select="."/>
      </xsl:element>
    </xsl:for-each>
  </numbers>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 16th, 2007, 01:00 PM
Authorized User
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent! Thank you very much for your time :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Map Coordinates dragondayz VB How-To 2 May 8th, 2006 10:52 AM
Image Coordinates everest ASP.NET 1.0 and 1.1 Basics 1 October 18th, 2005 11:54 PM
Draw Line from coordinates marcin2k Access VBA 1 October 14th, 2005 01:41 PM
pixel coordinates david.iulian Classic ASP Basics 0 March 31st, 2005 07:03 AM
coordinates buzzfever Beginning VB 6 1 September 23rd, 2003 05:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.