xsl:stylesheet auswerten

daniel665

Grünschnabel
Hallo kann mir jemand das xsl stylesheet erklären für folgendes xml Dokument?

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="WasTueIch.xsl"?>
<shapes>
<rectangle width="10" height="30"/>
<square side="15" />
<rectangle width="3" height="80"/>
<circle radius="10"/>
</shapes>

xsl stylesheet:
Probleme hab ich vorallem mit den variablen und parameter welche Werte sie annehmen und . Es wäre super wenn mir jemand erklären könnte wie man so ein stylesheet lesen kann um vorherzusagen was dabei rauskommt.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:eek:utput method="html"/>

<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Rekursion extrem</TITLE>
</HEAD>
<BODY>
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="rectangle" mode="area">
<xsl:value-of select="@width * @height"/>
</xsl:template>

<xsl:template match="square" mode="area">
<xsl:value-of select="@side * @side"/>
</xsl:template>

<xsl:template match="circle" mode="area">
<xsl:value-of select="3.14159 * @radius * @radius"/>
</xsl:template>

<xsl:template match="shapes">
<xsl:call-template name="WasTueIch">
<xsl:with-param name="set-of-shapes" select="*"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="WasTueIch">
<xsl:param name="set-of-shapes"/>
<xsl:choose>
<xsl:when test="count($set-of-shapes) != 0">
<xsl:variable name="first">
<xsl:apply-templates select="$set-of-shapes[1]" mode="area"/>
</xsl:variable>
<xsl:variable name="rest">
<xsl:call-template name="WasTueIch">
<xsl:with-param name="set-of-shapes" select="$set-of-shapes[position()!=1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$first + $rest"/>
</xsl:when>
<xsl:eek:therwise>0</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>


Vielen Dank im voraus
Daniel
 
Zuletzt bearbeitet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:eek:utput method="html" indent="yes"/>

<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Rekursion extrem</TITLE>
</HEAD>
<BODY>
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="rectangle">
<h1>Rechteck</h1>
<h2>Ergebniss : <xsl:value-of select="@width * @height"/></h2>
</xsl:template>

<xsl:template match="square">
<h1>Qurad</h1>
<h2>Ergebniss : <xsl:value-of select="@side * @side"/></h2>
</xsl:template>

<xsl:template match="circle">
<h1>Kreis</h1>
<h2>Ergebniss : <xsl:value-of select="3.14159 * @radius * @radius"/></h2>
</xsl:template>

<xsl:template match="shapes">
<h1>WasTueIch</h1>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>


ergibt


<HTML xmlns:fo="http://www.w3.org/1999/XSL/Format">
<HEAD>
<meta http-equiv="Content-Type" content="text/html">
<TITLE>Rekursion extrem</TITLE>
</HEAD>
<BODY>
<h1>WasTueIch</h1>

<h1>Rechteck</h1>
<h2>Ergebniss : 300</h2>

<h1>Qurad</h1>
<h2>Ergebniss : 225</h2>

<h1>Rechteck</h1>
<h2>Ergebniss : 240</h2>

<h1>Kreis</h1>
<h2>Ergebniss : 314.159</h2>

</BODY>
</HTML>

der parser ist schon rekursiv es müssen nur die Template angeben werden
 
Zurück