1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/VerySimple/Resources/structure_types.xsl Tue Jul 19 21:02:55 2005 +0000
1.3 @@ -0,0 +1,101 @@
1.4 +<?xml version="1.0" encoding="utf-8"?>
1.5 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1.6 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"
1.7 + version="1.0">
1.8 +
1.9 + <xsl:param name="types"/>
1.10 +
1.11 + <!-- Add or process type elements inside item elements. -->
1.12 +
1.13 + <xsl:template match="item">
1.14 + <!-- Copy the element and its contents. -->
1.15 + <xsl:copy>
1.16 + <xsl:apply-templates select="@*"/>
1.17 + <!-- Look for a type element. -->
1.18 + <xsl:choose>
1.19 + <xsl:when test="types">
1.20 + <!-- Use the existing types element. -->
1.21 + <xsl:apply-templates select="types"/>
1.22 + </xsl:when>
1.23 + <xsl:otherwise>
1.24 + <!-- Add a types element if none was found. -->
1.25 + <xsl:call-template name="types"/>
1.26 + </xsl:otherwise>
1.27 + </xsl:choose>
1.28 + <xsl:apply-templates select="*[local-name() != 'types']"/>
1.29 + </xsl:copy>
1.30 + </xsl:template>
1.31 +
1.32 + <!-- Investigate types elements. -->
1.33 +
1.34 + <xsl:template name="types">
1.35 + <!-- Make the element. -->
1.36 + <types>
1.37 + <xsl:call-template name="type"/>
1.38 + </types>
1.39 + </xsl:template>
1.40 +
1.41 + <xsl:template match="types">
1.42 + <!-- Copy the element. -->
1.43 + <xsl:copy>
1.44 + <xsl:apply-templates select="@*"/>
1.45 + <!-- Look for a type element. -->
1.46 + <xsl:choose>
1.47 + <xsl:when test="type">
1.48 + <!-- Use the existing type element. -->
1.49 + <xsl:apply-templates select="type"/>
1.50 + </xsl:when>
1.51 + <xsl:otherwise>
1.52 + <!-- Add a type element if none was found. -->
1.53 + <xsl:call-template name="type"/>
1.54 + </xsl:otherwise>
1.55 + </xsl:choose>
1.56 + <xsl:apply-templates select="*[local-name() != 'type']"/>
1.57 + </xsl:copy>
1.58 + </xsl:template>
1.59 +
1.60 + <!-- Investigate type elements. -->
1.61 +
1.62 + <xsl:template name="type">
1.63 + <!-- Make the element. -->
1.64 + <type>
1.65 + <xsl:call-template name="type-enum"/>
1.66 + </type>
1.67 + </xsl:template>
1.68 +
1.69 + <xsl:template match="type">
1.70 + <!-- Copy the element. -->
1.71 + <xsl:copy>
1.72 + <xsl:apply-templates select="@*"/>
1.73 + <xsl:call-template name="type-enum">
1.74 + <!-- Use the value of the element. -->
1.75 + <xsl:with-param name="value" select="@value"/>
1.76 + </xsl:call-template>
1.77 + </xsl:copy>
1.78 + </xsl:template>
1.79 +
1.80 + <!-- Add to type elements the range of acceptable values. -->
1.81 +
1.82 + <xsl:template name="type-enum">
1.83 + <xsl:param name="value"/>
1.84 + <!-- Find all values in the range and add them. -->
1.85 + <xsl:for-each select="$types/types/type-enum">
1.86 + <xsl:copy>
1.87 + <xsl:apply-templates select="@*"/>
1.88 + <!-- Mark those whose value are the same as that found on the element. -->
1.89 + <xsl:if test="$value = @value">
1.90 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.91 + </xsl:if>
1.92 + </xsl:copy>
1.93 + </xsl:for-each>
1.94 + </xsl:template>
1.95 +
1.96 + <!-- Replicate unknown elements. -->
1.97 +
1.98 + <xsl:template match="@*|*|node()">
1.99 + <xsl:copy>
1.100 + <xsl:apply-templates select="@*|*|node()"/>
1.101 + </xsl:copy>
1.102 + </xsl:template>
1.103 +
1.104 +</xsl:stylesheet>