XML to CSV via XSL

Joined
Jun 20, 2008
Messages
2
Reaction score
0
Hi,

I try to write a XSL to create a CSV file from a XML file.
This is my XML
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
  <Placemark>
    <visibility>0</visibility>
    <description><![CDATA[12, <a href="http://www.scdb.info/software/statistik_detail.php?sc_language_selector=en&speedtraps_id=12" target="_blank">More details</a>]]></description>
    <styleUrl>#SCDB_130kmh</styleUrl>
    <Point>
      <extrude>1</extrude>
      <altitudeMode>relativeToGround</altitudeMode>
      <coordinates>13.73872,46.65472,9.999999999999998</coordinates>
    </Point>
  </Placemark>
  <Placemark>
    <visibility>0</visibility>
    <description><![CDATA[2694, <a href="http://www.scdb.info/software/statistik_detail.php?sc_language_selector=en&speedtraps_id=2694" target="_blank">More details</a>]]></description>
    <styleUrl>#SCDB_50kmh</styleUrl>
    <Point>
      <extrude>1</extrude>
      <altitudeMode>relativeToGround</altitudeMode>
      <coordinates>15.64997,48.21369,9.999999999999998</coordinates>
    </Point>
  </Placemark>
</Document>

The output should be the following for this XML:
#SCDB_130km/h,13.73872,46.65472,9.999999999999998

Only Placemarks with #SCDB_130km/h should be written to the file

I've written this XSL but this is far away from my result :)

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="/Document">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="/Placemark">
  <xsl:if test="styleUrl=SCDB_130kmh">
    <xsl:for-each select="styleUrl">
      <xsl:value-of select="."/>;<xsl:text/>
    </xsl:for-each>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

Thanks skopeko

P.S: I'm using Xalan
 
Joined
Jun 20, 2008
Messages
2
Reaction score
0
Ok. I found it.

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="/">
<xsl:for-each select="Document/Placemark">
  <xsl:if test="styleUrl='#SCDB_130kmh'">
    <xsl:value-of select="styleUrl"/>,<xsl:text/>
    <xsl:value-of select="Point/coordinates"/><xsl:text/>
    <xsl:text>
</xsl:text>
  </xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top