hi, damit es auch mal konkreter wird mit xalan/xslt -und ich nicht aus der Übung komme:

jan’s Daten in “sauberes” XML-Format gebracht: 2 Zeilen am Anfang, eine am Ende - sonst ist nix mit xslt. Hab den Way-Point mal verdoppelt, damit man das Format besser sieht.


<?xml version="1.0" encoding="ISO-8859-1"?>
<liste>
<wpt lat="52.0065863" lon="9.1826286">
    <ele>171.0000000</ele>
    <name>1003-Sonneborn</name>
    <cmt>Meilenstein, lippisch, kleine Stele</cmt>
    <desc>Meilenstein, lippisch, kleine Stele</desc>
    <sym>City (Large)</sym>
    <extensions>
      <gpxx:WaypointExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
        <gpxx:DisplayMode>SymbolOnly</gpxx:DisplayMode>
      </gpxx:WaypointExtension>
    </extensions>
  </wpt>
  <wpt lat="52.0065863" lon="9.1826286">
    <ele>171.0000000</ele>
    <name>1003-Sonneborn</name>
    <cmt>Meilenstein, lippisch, kleine Stele</cmt>
    <desc>Meilenstein, lippisch, kleine Stele</desc>
    <sym>City (Large)</sym>
    <extensions>
      <gpxx:WaypointExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
        <gpxx:DisplayMode>SymbolOnly</gpxx:DisplayMode>
      </gpxx:WaypointExtension>
    </extensions>
  </wpt>
</liste>

XSL:


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

 <xsl:template name="NL"><xsl:text>
</xsl:text>
 </xsl:template>

 <xsl:template match="/">
 <xsl:call-template name="NL" /><osm version="0.6" generator="xalan"><xsl:call-template name="NL" />
   <xsl:for-each select="liste/wpt">
      <node>
        <xsl:attribute name="id"><xsl:number value="-position()" format="1" /></xsl:attribute>
        <xsl:attribute name="lat"><xsl:value-of select="@lat" /></xsl:attribute> 
        <xsl:attribute name="lon"><xsl:value-of select="@lon" /></xsl:attribute>
        <xsl:call-template name="NL" />
        <tag k="historic" v="milestone"/><xsl:call-template name="NL" />
        <tag k="ele"><xsl:attribute name="v"><xsl:value-of select="ele" /></xsl:attribute> </tag><xsl:call-template name="NL" />
        <tag k="note"><xsl:attribute name="v"><xsl:value-of select="name" /></xsl:attribute> </tag><xsl:call-template name="NL" />
        <tag k="comment"><xsl:attribute name="v"><xsl:value-of select="cmt" /></xsl:attribute> </tag><xsl:call-template name="NL" />
        <tag k="description"><xsl:attribute name="v"><xsl:value-of select="desc" /></xsl:attribute> </tag><xsl:call-template name="NL" />
        <tag k="symbol"><xsl:attribute name="v"><xsl:value-of select="sym" /></xsl:attribute> </tag><xsl:call-template name="NL" />
      </node><xsl:call-template name="NL" />
   </xsl:for-each>
 </osm>
 </xsl:template>
</xsl:stylesheet>

dieses “komische” NL-Template macht jeweils ein Linefeed - nur für die Optik, josm braucht das nicht.
Achtung: der Zeilenvorschub IM Template ist lebensnotwendig.

Aufruf: ** xalan -in jan.xml -xsl jan.xsl -out jan.osm**

Ergebnis:


<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="xalan">
<node id="-1" lat="52.0065863" lon="9.1826286">
<tag k="historic" v="milestone"/>
<tag k="ele" v="171.0000000"/>
<tag k="note" v="1003-Sonneborn"/>
<tag k="comment" v="Meilenstein, lippisch, kleine Stele"/>
<tag k="description" v="Meilenstein, lippisch, kleine Stele"/>
<tag k="symbol" v="City (Large)"/>
</node>
<node id="-2" lat="52.0065863" lon="9.1826286">
<tag k="historic" v="milestone"/>
<tag k="ele" v="171.0000000"/>
<tag k="note" v="1003-Sonneborn"/>
<tag k="comment" v="Meilenstein, lippisch, kleine Stele"/>
<tag k="description" v="Meilenstein, lippisch, kleine Stele"/>
<tag k="symbol" v="City (Large)"/>
</node>
</osm>

Was will man mehr?

Gruss
Walter

p.s. hab es mit sudo apt-get install xalan installiert.