* moved retrieval of propertyName into extra template

* moved global variables into stylesheet element
* simplified the sorting of properties
* renamed property tempalte to getOutputItem
* added comments
This commit is contained in:
Tobi Schäfer 2004-07-12 15:58:27 +00:00
parent 9192cde250
commit 4f33588483

View file

@ -8,9 +8,13 @@
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:variable name="id" select="/xmlroot/hopobject/@id"/>
<xsl:variable name="id" select="/xmlroot/hopobject/@id"/>
<xsl:variable name="name" select="/xmlroot/hopobject/@name"/>
<xsl:variable name="prototype" select="/xmlroot/hopobject/@prototype"/>
<xsl:variable name="parent" select="/xmlroot/hopobject/hop:parent"/>
<xsl:variable name="children" select="/xmlroot/hopobject/hop:child"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="$id"/>.xml (Hop XML Database File)</title>
@ -18,6 +22,7 @@
</head>
<body bgcolor="white">
<!-- main navigation -->
<h2>
<xsl:if test="$id = 0">root</xsl:if>
<xsl:if test="$id &gt; 0">
@ -25,31 +30,28 @@
</xsl:if>
</h2>
<!-- table header -->
<table border="0" cellspacing="1" cellpadding="5" bgcolor="gray">
<tr bgcolor="white">
<th>Name</th>
<th>Value</th>
</tr>
<xsl:variable name="name" select="/xmlroot/hopobject/@name"/>
<!-- _name, _prototype and _parent properties -->
<xsl:if test="$name">
<xsl:call-template name="property">
<xsl:call-template name="getOutputItem">
<xsl:with-param name="name">_name</xsl:with-param>
<xsl:with-param name="value" select="$name"/>
</xsl:call-template>
</xsl:if>
<xsl:variable name="prototype" select="/xmlroot/hopobject/@prototype"/>
<xsl:if test="$prototype">
<xsl:call-template name="property">
<xsl:call-template name="getOutputItem">
<xsl:with-param name="name">_prototype</xsl:with-param>
<xsl:with-param name="value" select="$prototype"/>
</xsl:call-template>
</xsl:if>
<xsl:variable name="parent" select="/xmlroot/hopobject/hop:parent"/>
<xsl:if test="$parent">
<xsl:call-template name="property">
<xsl:call-template name="getOutputItem">
<xsl:with-param name="name">_parent</xsl:with-param>
<xsl:with-param name="value">
HopObject <xsl:value-of select="$parent/@idref"/>
@ -60,12 +62,12 @@
</xsl:call-template>
</xsl:if>
<xsl:variable name="children" select="/xmlroot/hopobject/hop:child"/>
<!-- _children collection -->
<xsl:if test="count($children) &gt; 0">
<tr bgcolor="white">
<td valign="top" nowrap="nowrap">_children</td>
<td>
<xsl:for-each select="/xmlroot/hopobject/hop:child">
<xsl:for-each select="$children">
<xsl:sort select="@idref" data-type="number"/>
<a href="{@idref}.xml"><nowrap><xsl:value-of select="@prototyperef"/>
<xsl:text> </xsl:text><xsl:value-of select="@idref"/></nowrap></a>
@ -77,22 +79,16 @@
</tr>
</xsl:if>
<!-- primitive properties -->
<xsl:for-each select="/xmlroot/hopobject/*">
<xsl:sort select="normalize-space(concat(@propertyname, ' ' , name()))"/>
<xsl:sort select="concat(@propertyname, name())"/>
<xsl:choose>
<xsl:when test="name() = 'hop:parent'"/>
<xsl:when test="name() = 'hop:child'"/>
<xsl:when test="@idref">
<xsl:call-template name="property">
<xsl:call-template name="getOutputItem">
<xsl:with-param name="name">
<!-- if element name is "property", property name is in an attribute called
"propertyname". Otherwise, the element name is the property name -->
<xsl:if test="name() = 'property'">
<xsl:value-of select="@propertyname"/>
</xsl:if>
<xsl:if test="name() != 'property'">
<xsl:value-of select="name()"/>
</xsl:if>
<xsl:call-template name="getPropertyName"/>
</xsl:with-param>
<xsl:with-param name="value">
HopObject <xsl:value-of select="@idref"/>
@ -103,16 +99,9 @@
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="property">
<xsl:call-template name="getOutputItem">
<xsl:with-param name="name">
<!-- if element name is "property", property name is in an attribute called
"propertyname". Otherwise, the element name is the property name -->
<xsl:if test="name() = 'property'">
<xsl:value-of select="@propertyname"/>
</xsl:if>
<xsl:if test="name() != 'property'">
<xsl:value-of select="name()"/>
</xsl:if>
<xsl:call-template name="getPropertyName"/>
</xsl:with-param>
<xsl:with-param name="value"><xsl:value-of select="text()"/></xsl:with-param>
</xsl:call-template>
@ -125,39 +114,56 @@
</html>
</xsl:template>
<xsl:template name="property">
<!-- helper template to compose a hopobject's name -->
<xsl:template name="getName">
<xsl:param name="name"/>
<xsl:choose>
<xsl:when test="substring-after($name, 'HopObject ') = '0'">
root
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- helper template to compose a property's name: if the element's
name is "property", the property name is in an attribute called
"propertyname". Otherwise, the element name is the element's name -->
<xsl:template name="getPropertyName">
<xsl:choose>
<xsl:when test="name() = 'property'">
<xsl:value-of select="@propertyname"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- helper template to compose a table row containing a property's data -->
<xsl:template name="getOutputItem">
<xsl:param name="name"/>
<xsl:param name="type"/>
<xsl:param name="href"/>
<xsl:param name="value"/>
<xsl:param name="display">
<xsl:param name="href"/>
<xsl:variable name="display">
<xsl:call-template name="getName">
<xsl:with-param name="name" select="$value"/>
</xsl:call-template>
</xsl:param>
</xsl:variable>
<tr bgcolor="white">
<td valign="top" nowrap="nowrap"><xsl:value-of select="$name"/></td>
<td><xsl:if test="$href">
<a href="{$href}"><xsl:value-of select="$display"/></a>
</xsl:if>
<xsl:if test="$href = ''">
<xsl:value-of select="$display"/>
</xsl:if>
</td>
<td><xsl:choose>
<xsl:when test="$href">
<a href="{$href}"><xsl:value-of select="$display"/></a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$display"/>
</xsl:otherwise>
</xsl:choose></td>
</tr>
</xsl:template>
<xsl:template name="getName">
<xsl:param name="name"/>
<xsl:param name="isRoot" select="substring-after($name, 'HopObject ') = '0'"/>
<xsl:if test="$isRoot">
root
</xsl:if>
<xsl:if test="$isRoot = false">
<xsl:value-of select="$name"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>