1.1 --- a/XSLForms/XSL/Schema.xsl Fri Jan 27 00:44:13 2006 +0000
1.2 +++ b/XSLForms/XSL/Schema.xsl Fri Jan 27 17:00:08 2006 +0000
1.3 @@ -18,7 +18,9 @@
1.4 -->
1.5 <xsl:stylesheet version="1.0"
1.6 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1.7 - xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
1.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"
1.9 + xmlns:str="http://exslt.org/strings"
1.10 + extension-element-prefixes="str">
1.11
1.12 <xsl:output indent="yes"/>
1.13
1.14 @@ -35,7 +37,7 @@
1.15
1.16 <!-- Match element references. -->
1.17
1.18 - <xsl:template match="*[@template:element]">
1.19 + <xsl:template match="*[@template:element]" priority="1">
1.20 <xsl:call-template name="enter-element">
1.21 <xsl:with-param name="other-elements" select="@template:element"/>
1.22 <xsl:with-param name="other-init" select="@template:init"/>
1.23 @@ -72,30 +74,43 @@
1.24 <xsl:param name="remaining-elements"/>
1.25 <xsl:param name="first-init"/>
1.26 <xsl:param name="remaining-init"/>
1.27 - <element>
1.28 - <xsl:attribute name="name"><xsl:value-of select="$first-element"/></xsl:attribute>
1.29 - <xsl:if test="$first-init != ''">
1.30 - <xsl:attribute name="init"><xsl:value-of select="$first-init"/></xsl:attribute>
1.31 - </xsl:if>
1.32 - <xsl:choose>
1.33 - <xsl:when test="$remaining-elements = ''">
1.34 - <xsl:call-template name="enter-attribute"/>
1.35 - </xsl:when>
1.36 - <xsl:otherwise>
1.37 - <xsl:call-template name="enter-element">
1.38 - <xsl:with-param name="other-elements" select="$remaining-elements"/>
1.39 - <xsl:with-param name="other-init" select="$remaining-init"/>
1.40 - </xsl:call-template>
1.41 - </xsl:otherwise>
1.42 - </xsl:choose>
1.43 - </element>
1.44 + <!-- Test for recursive references. -->
1.45 + <xsl:variable name="recursive-element" select="ancestor::*[$first-element = str:split(@template:element, ',')[1]]"/>
1.46 + <xsl:choose>
1.47 + <!-- Generate a reference to the previous element definition. -->
1.48 + <xsl:when test="$recursive-element">
1.49 + <element-ref>
1.50 + <xsl:attribute name="name"><xsl:value-of select="$first-element"/></xsl:attribute>
1.51 + </element-ref>
1.52 + </xsl:when>
1.53 + <!-- Generate a normal, nested element definition. -->
1.54 + <xsl:otherwise>
1.55 + <element>
1.56 + <xsl:attribute name="name"><xsl:value-of select="$first-element"/></xsl:attribute>
1.57 + <xsl:if test="$first-init != ''">
1.58 + <xsl:attribute name="init"><xsl:value-of select="$first-init"/></xsl:attribute>
1.59 + </xsl:if>
1.60 + <xsl:choose>
1.61 + <xsl:when test="$remaining-elements = ''">
1.62 + <xsl:call-template name="enter-attribute"/>
1.63 + </xsl:when>
1.64 + <xsl:otherwise>
1.65 + <xsl:call-template name="enter-element">
1.66 + <xsl:with-param name="other-elements" select="$remaining-elements"/>
1.67 + <xsl:with-param name="other-init" select="$remaining-init"/>
1.68 + </xsl:call-template>
1.69 + </xsl:otherwise>
1.70 + </xsl:choose>
1.71 + </element>
1.72 + </xsl:otherwise>
1.73 + </xsl:choose>
1.74 </xsl:template>
1.75
1.76
1.77
1.78 <!-- Match attributes. -->
1.79
1.80 - <xsl:template match="*[not(@template:element) and (@template:attribute or @template:attribute-field or @template:attribute-area or @template:attribute-button or @template:attribute-list-button or @template:selector-field or @template:multiple-choice-field or @template:multiple-choice-list-field or @template:multiple-choice-value or @template:multiple-choice-list-value) or @template:multiple-choice-list-element]">
1.81 + <xsl:template match="*[@template:attribute or @template:attribute-field or @template:attribute-area or @template:attribute-button or @template:attribute-list-button or @template:selector-field or @template:multiple-choice-field or @template:multiple-choice-list-field or @template:multiple-choice-value or @template:multiple-choice-list-value or @template:multiple-choice-list-element]">
1.82 <xsl:call-template name="enter-attribute"/>
1.83 </xsl:template>
1.84