Tecnologías XML / XSLT / XSLT 3.0 / Streaming XSLT / Primeros pasos con el streaming XSLT / xsl:mode on-no-match / on-no-match="shallow-copy"

Ejercicio 2

Utilice el modo on-no-match="shallow-copy", para renombrar el elemento city y el atributo value del archivo openWeather.xml en stadt y wert, respectivamente. El resto del documento debe copiarse sin cambios a la salida. Véase el siguiente ejemplo de código:

Ejemplo de código: salida requerida para el ejercicio 2 (extracto).

<cityWeather>
  <current>
    <stadt id="2950159" name="Berlin"/>
    <TEMP value="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>
  ...       
</cityWeather>

La transformación ha renombrado city en stadt y value en wert.

Utilice el escenario de transformación [Übung 2] on-no-match="shallow-copy" (XML >> XML) (véanse las explicaciones de los ejercicios) y el siguiente archivo XSLT :

Ejemplo de código: hoja de estilo para el ejercicio 2 sobre xsl:mode on-no-match="shallow-copy".

<?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">
  <!--AUFGABE: Nutzen Sie on-no-match="shallow-copy", um das Element city und das Attribut @value umzubenennen. Der Rest der XML-Datei soll unverändert in den Output übernommen werden. -->
    <!--TODO: Streaming-Modus und on-no-match definieren.-->
    <!--TODO: Entsprechende Templates anlegen.-->    
</xsl:stylesheet>

Ampliación

Escriba otra plantilla, que renombre el atributo name del elemento city en ortsname.

¿Qué ocurre? ¿Y por qué?

Solución

El XML de salida completo y la hoja de estilo de solución se encuentran en Soluciones del ejercicio 2 — xsl:mode on-no-match="shallow-copy".

   

volver arriba