1.1 --- a/examples/Common/VerySimple/Resources/structure_template.xhtml Tue Jul 19 21:02:23 2005 +0000
1.2 +++ b/examples/Common/VerySimple/Resources/structure_template.xhtml Tue Jul 19 21:02:55 2005 +0000
1.3 @@ -16,6 +16,13 @@
1.4 Some item: <input template:attribute="value" name="{template:field-name()}" type="text" value="{$this-value}" />
1.5 <input name="remove={template:this-position()}" type="submit" value="Remove" />
1.6 </p>
1.7 + <p template:element="types">
1.8 + Item type:
1.9 + <select template:element="type" name="{template:multi-field-name('value')}">
1.10 + <option template:element="type-enum" template:expr="@value-is-set" template:expr-attr="selected"
1.11 + template:value="@value" value="{@value}"></option>
1.12 + </select>
1.13 + </p>
1.14 <p>
1.15 Itself containing more items:
1.16 </p>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/VerySimple/Resources/structure_types.xml Tue Jul 19 21:02:55 2005 +0000
2.3 @@ -0,0 +1,7 @@
2.4 +<?xml version="1.0"?>
2.5 +<types>
2.6 + <type-enum value="(Not selected)"/>
2.7 + <type-enum value="Important"/>
2.8 + <type-enum value="Not important"/>
2.9 + <type-enum value="Personal"/>
2.10 +</types>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/examples/Common/VerySimple/Resources/structure_types.xsl Tue Jul 19 21:02:55 2005 +0000
3.3 @@ -0,0 +1,101 @@
3.4 +<?xml version="1.0" encoding="utf-8"?>
3.5 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3.6 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"
3.7 + version="1.0">
3.8 +
3.9 + <xsl:param name="types"/>
3.10 +
3.11 + <!-- Add or process type elements inside item elements. -->
3.12 +
3.13 + <xsl:template match="item">
3.14 + <!-- Copy the element and its contents. -->
3.15 + <xsl:copy>
3.16 + <xsl:apply-templates select="@*"/>
3.17 + <!-- Look for a type element. -->
3.18 + <xsl:choose>
3.19 + <xsl:when test="types">
3.20 + <!-- Use the existing types element. -->
3.21 + <xsl:apply-templates select="types"/>
3.22 + </xsl:when>
3.23 + <xsl:otherwise>
3.24 + <!-- Add a types element if none was found. -->
3.25 + <xsl:call-template name="types"/>
3.26 + </xsl:otherwise>
3.27 + </xsl:choose>
3.28 + <xsl:apply-templates select="*[local-name() != 'types']"/>
3.29 + </xsl:copy>
3.30 + </xsl:template>
3.31 +
3.32 + <!-- Investigate types elements. -->
3.33 +
3.34 + <xsl:template name="types">
3.35 + <!-- Make the element. -->
3.36 + <types>
3.37 + <xsl:call-template name="type"/>
3.38 + </types>
3.39 + </xsl:template>
3.40 +
3.41 + <xsl:template match="types">
3.42 + <!-- Copy the element. -->
3.43 + <xsl:copy>
3.44 + <xsl:apply-templates select="@*"/>
3.45 + <!-- Look for a type element. -->
3.46 + <xsl:choose>
3.47 + <xsl:when test="type">
3.48 + <!-- Use the existing type element. -->
3.49 + <xsl:apply-templates select="type"/>
3.50 + </xsl:when>
3.51 + <xsl:otherwise>
3.52 + <!-- Add a type element if none was found. -->
3.53 + <xsl:call-template name="type"/>
3.54 + </xsl:otherwise>
3.55 + </xsl:choose>
3.56 + <xsl:apply-templates select="*[local-name() != 'type']"/>
3.57 + </xsl:copy>
3.58 + </xsl:template>
3.59 +
3.60 + <!-- Investigate type elements. -->
3.61 +
3.62 + <xsl:template name="type">
3.63 + <!-- Make the element. -->
3.64 + <type>
3.65 + <xsl:call-template name="type-enum"/>
3.66 + </type>
3.67 + </xsl:template>
3.68 +
3.69 + <xsl:template match="type">
3.70 + <!-- Copy the element. -->
3.71 + <xsl:copy>
3.72 + <xsl:apply-templates select="@*"/>
3.73 + <xsl:call-template name="type-enum">
3.74 + <!-- Use the value of the element. -->
3.75 + <xsl:with-param name="value" select="@value"/>
3.76 + </xsl:call-template>
3.77 + </xsl:copy>
3.78 + </xsl:template>
3.79 +
3.80 + <!-- Add to type elements the range of acceptable values. -->
3.81 +
3.82 + <xsl:template name="type-enum">
3.83 + <xsl:param name="value"/>
3.84 + <!-- Find all values in the range and add them. -->
3.85 + <xsl:for-each select="$types/types/type-enum">
3.86 + <xsl:copy>
3.87 + <xsl:apply-templates select="@*"/>
3.88 + <!-- Mark those whose value are the same as that found on the element. -->
3.89 + <xsl:if test="$value = @value">
3.90 + <xsl:attribute name="value-is-set">true</xsl:attribute>
3.91 + </xsl:if>
3.92 + </xsl:copy>
3.93 + </xsl:for-each>
3.94 + </xsl:template>
3.95 +
3.96 + <!-- Replicate unknown elements. -->
3.97 +
3.98 + <xsl:template match="@*|*|node()">
3.99 + <xsl:copy>
3.100 + <xsl:apply-templates select="@*|*|node()"/>
3.101 + </xsl:copy>
3.102 + </xsl:template>
3.103 +
3.104 +</xsl:stylesheet>