Lösungen zu Übung 2 — xsl:mode on-no-match="shallow-copy"

Im Folgenden finden Sie die Lösungsdateien zu Übung 2 unter xsl:mode on-no-match="shallow-copy".

Code-Beispiel: Lösungs-XSLT zu Übung 2.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math" version="3.0">   
  <xsl:mode  streamable="yes" on-no-match="shallow-copy"/>   
  <!--Elemente umbenennen-->
  <xsl:template match="@value">
    <xsl:attribute name="wert">
      <!--Rest des aktuellen Knoten wird übenommen und eingefügt-->
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>  
  <!--Knoten umbennenen-->    
  <xsl:template match="city">
    <stadt>           
      <xsl:copy-of select="@*"/>
    </stadt>
  </xsl:template>    
</xsl:stylesheet>

Code-Beispiel: Vollständiges Output-XML zu Übung 2.

<?xml version="1.0" encoding="UTF-8"?>
<cityWeather>
  <current>
    <stadt id="2950159" name="Berlin"/>
    <temperature wert="284.15" min="284.15" max="284.15" unit="kelvin"/>
    <humidity wert="76" unit="%"/>
    <pressure wert="1031" unit="hPa"/>
    <wind>
      <speed wert="3.1" name="Light breeze"/>
      <gusts/>
      <direction wert="150" code="SSE" name="South-southeast"/>
    </wind>
    <clouds wert="0" name="clear sky"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="800" wert="Sky is Clear" icon="01d"/>
    <lastupdate wert="2015-12-08T11:20:00"/>
  </current>
  <current>
    <stadt id="2643743" name="London"/>
    <temperature wert="286.29" min="286.15" max="287.15" unit="kelvin"/>
    <humidity wert="82" unit="%"/>
    <pressure wert="1020" unit="hPa"/>
    <wind>
      <speed wert="5.1" name="Gentle Breeze"/>
      <gusts/>
      <direction wert="210" code="SSW" name="South-southwest"/>
    </wind>
    <clouds wert="20" name="few clouds"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="500" wert="light rain" icon="10d"/>
    <lastupdate wert="2015-12-08T11:50:00"/>
  </current>
  <current>
    <stadt id="2988507" name="Paris"/>
    <temperature wert="283.15" min="282.15" max="284.15" unit="kelvin"/>
    <humidity wert="81" unit="%"/>
    <pressure wert="1028" unit="hPa"/>
    <wind>
      <speed wert="2.6" name="Light breeze"/>
      <gusts/>
      <direction wert="190" code="S" name="South"/>
    </wind>
    <clouds wert="75" name="broken clouds"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="803" wert="broken clouds" icon="04d"/>
    <lastupdate wert="2015-12-08T11:00:00"/>
  </current>
  <current>
    <stadt id="2825297" name="Stuttgart"/>
    <temperature wert="281.39" min="280.15" max="282.15" unit="kelvin"/>
    <humidity wert="87" unit="%"/>
    <pressure wert="1031" unit="hPa"/>
    <wind>
      <speed wert="1.5" name="Calm"/>
      <gusts/>
      <direction wert="130" code="SE" name="SouthEast"/>
    </wind>
    <clouds wert="0" name="clear sky"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="800" wert="Sky is Clear" icon="01d"/>
    <lastupdate wert="2015-12-08T11:50:00"/>
  </current>
  <current>
    <stadt id="3054643" name="Budapest"/>
    <temperature wert="278.15" min="278.15" max="278.15" unit="kelvin"/>
    <humidity wert="93" unit="%"/>
    <pressure wert="1038" unit="hPa"/>
    <wind>
      <speed wert="2.1" name="Light breeze"/>
      <gusts/>
      <direction wert="100" code="E" name="East"/>
    </wind>
    <clouds wert="90" name="overcast clouds"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="701" wert="mist" icon="50d"/>
    <lastupdate wert="2015-12-08T11:00:00"/>
  </current>
  <current>
    <stadt id="2673730" name="Stockholm"/>
    <temperature wert="276.09" min="275.15" max="277.15" unit="kelvin"/>
    <humidity wert="89" unit="%"/>
    <pressure wert="1030" unit="hPa"/>
    <wind>
      <speed wert="2.6" name="Light breeze"/>
      <gusts/>
      <direction wert="180" code="S" name="South"/>
    </wind>
    <clouds wert="0" name="clear sky"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="800" wert="Sky is Clear" icon="01d"/>
    <lastupdate wert="2015-12-08T11:50:00"/>
  </current>
  <current>
    <stadt id="3143244" name="Oslo"/>
    <temperature wert="273.15" min="273.15" max="273.15" unit="kelvin"/>
    <humidity wert="98" unit="%"/>
    <pressure wert="1023" unit="hPa"/>
    <wind>
      <speed wert="0.5" name="Calm"/>
      <gusts/>
      <direction wert="0" code="N" name="North"/>
    </wind>
    <clouds wert="75" name="broken clouds"/>
    <visibility wert="1600"/>
    <precipitation mode="no"/>
    <weather number="701" wert="mist" icon="50d"/>
    <lastupdate wert="2015-12-08T11:20:00"/>
  </current>
  <current>
    <stadt id="3143244" name="Oslo"/>
    <temperature wert="273.15" min="273.15" max="273.15" unit="kelvin"/>
    <humidity wert="98" unit="%"/>
    <pressure wert="1023" unit="hPa"/>
    <wind>
      <speed wert="0.5" name="Calm"/>
      <gusts/>
      <direction wert="0" code="N" name="North"/>
    </wind>
    <clouds wert="75" name="broken clouds"/>
    <visibility wert="1600"/>
    <precipitation mode="no"/>
    <weather number="701" wert="mist" icon="50d"/>
    <lastupdate wert="2015-12-08T11:20:00"/>
  </current>
  <current>
    <stadt id="2661552" name="Bern"/>
    <temperature wert="276.47" min="276.15" max="277.15" unit="kelvin"/>
    <humidity wert="100" unit="%"/>
    <pressure wert="1033" unit="hPa"/>
    <wind>
      <speed wert="1.5" name="Calm"/>
      <gusts/>
      <direction wert="0" code="N" name="North"/>
    </wind>
    <clouds wert="75" name="broken clouds"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="701" wert="mist" icon="50d"/>
    <lastupdate wert="2015-12-08T12:20:00"/>
  </current>
  <current>
    <stadt id="2761367" name="Wien"/>
    <temperature wert="276.15" min="276.15" max="276.15" unit="kelvin"/>
    <humidity wert="100" unit="%"/>
    <pressure wert="1035" unit="hPa"/>
    <wind>
      <speed wert="8.2" name="Fresh Breeze"/>
      <gusts/>
      <direction wert="140" code="SE" name="SouthEast"/>
    </wind>
    <clouds wert="90" name="overcast clouds"/>
    <visibility wert="600"/>
    <precipitation mode="no"/>
    <weather number="741" wert="fog" icon="50d"/>
    <lastupdate wert="2015-12-08T11:50:00"/>
  </current>
  <current>
    <stadt id="524901" name="Moscow"/>
    <temperature wert="275.9" min="275.15" max="276.15" unit="kelvin"/>
    <humidity wert="59" unit="%"/>
    <pressure wert="1019" unit="hPa"/>
    <wind>
      <speed wert="11" name="Strong breeze"/>
      <gusts wert="17"/>
      <direction wert="300" code="WNW" name="West-northwest"/>
    </wind>
    <clouds wert="75" name="broken clouds"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="803" wert="broken clouds" icon="04d"/>
    <lastupdate wert="2015-12-08T11:30:00"/>
  </current>
  <current>
    <stadt id="6949461" name="Kopenhagen"/>
    <temperature wert="281.42" min="281.15" max="282.15" unit="kelvin"/>
    <humidity wert="100" unit="%"/>
    <pressure wert="1029" unit="hPa"/>
    <wind>
      <speed wert="6.7" name="Moderate breeze"/>
      <gusts/>
      <direction wert="170" code="S" name="South"/>
    </wind>
    <clouds wert="90" name="overcast clouds"/>
    <visibility/>
    <precipitation mode="no"/>
    <weather number="701" wert="mist" icon="50d"/>
    <lastupdate wert="2015-12-08T12:20:00"/>
  </current>
</cityWeather>
Tipp der data2type-Redaktion:
Zum Thema XSLT bieten wir auch folgende Schulungen zur Vertiefung und professionellen Fortbildung an: