1 <?xml version="1.0" encoding="utf-8"?> 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 xmlns:template="http://www.boddie.org.uk/ns/xmltools/template" 4 version="1.0"> 5 6 <xsl:param name="types"/> 7 8 <!-- Add or process type elements inside item elements. --> 9 10 <xsl:template match="item"> 11 <!-- Copy the element and its contents. --> 12 <xsl:copy> 13 <xsl:apply-templates select="@*"/> 14 <!-- Look for a type element. --> 15 <xsl:call-template name="type"/> 16 <xsl:apply-templates select="*[local-name() != 'type']"/> 17 </xsl:copy> 18 </xsl:template> 19 20 <!-- Investigate type elements. --> 21 22 <xsl:template name="type"> 23 <!-- Make the element. --> 24 <type> 25 <!-- Look for type element values. --> 26 <xsl:call-template name="type-enum"> 27 <!-- Supply the existing type-enum values. --> 28 <xsl:with-param name="values" select="type/type-enum/@value"/> 29 </xsl:call-template> 30 </type> 31 </xsl:template> 32 33 <!-- Add to type elements the range of acceptable values. --> 34 35 <xsl:template name="type-enum"> 36 <xsl:param name="values"/> 37 <!-- Find all values in the range and add them. --> 38 <xsl:for-each select="$types/types/type-enum"> 39 <xsl:copy> 40 <xsl:apply-templates select="@*"/> 41 <!-- Mark those whose value are the same as that found on the element. --> 42 <xsl:if test="$values[string() = current()/@value]"> 43 <xsl:attribute name="value-is-set">true</xsl:attribute> 44 </xsl:if> 45 </xsl:copy> 46 </xsl:for-each> 47 </xsl:template> 48 49 <!-- Replicate unknown elements. --> 50 51 <xsl:template match="@*|*|node()"> 52 <xsl:copy> 53 <xsl:apply-templates select="@*|*|node()"/> 54 </xsl:copy> 55 </xsl:template> 56 57 </xsl:stylesheet>