1 <?xml version="1.0" encoding="utf-8"?> 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 version="1.0"> 4 5 <xsl:param name="types"/> 6 7 <!-- Add or process type elements inside item elements. --> 8 9 <xsl:template match="item"> 10 <!-- Copy the element and its contents. --> 11 <xsl:copy> 12 <xsl:apply-templates select="@*"/> 13 <!-- Look for a type element. --> 14 <xsl:choose> 15 <xsl:when test="type"> 16 <!-- Use the existing type element. --> 17 <xsl:apply-templates select="type"/> 18 </xsl:when> 19 <xsl:otherwise> 20 <!-- Add a type element if none was found. --> 21 <xsl:call-template name="type"/> 22 </xsl:otherwise> 23 </xsl:choose> 24 <xsl:apply-templates select="*[local-name() != 'type']"/> 25 </xsl:copy> 26 </xsl:template> 27 28 <!-- Investigate type elements. --> 29 30 <xsl:template name="type"> 31 <!-- Make the element. --> 32 <type> 33 <xsl:call-template name="type-enum"/> 34 </type> 35 </xsl:template> 36 37 <xsl:template match="type"> 38 <!-- Copy the element. --> 39 <xsl:copy> 40 <xsl:apply-templates select="@*"/> 41 <xsl:call-template name="type-enum"> 42 <!-- Use the value of the element. --> 43 <xsl:with-param name="value" select="@value"/> 44 </xsl:call-template> 45 </xsl:copy> 46 </xsl:template> 47 48 <!-- Add to type elements the range of acceptable values. --> 49 50 <xsl:template name="type-enum"> 51 <xsl:param name="value"/> 52 <!-- Find all values in the range and add them. --> 53 <xsl:for-each select="$types/types/type-enum"> 54 <xsl:copy> 55 <xsl:apply-templates select="@*"/> 56 </xsl:copy> 57 </xsl:for-each> 58 </xsl:template> 59 60 <!-- Replicate unknown elements. --> 61 62 <xsl:template match="@*|*|node()"> 63 <xsl:copy> 64 <xsl:apply-templates select="@*|*|node()"/> 65 </xsl:copy> 66 </xsl:template> 67 68 </xsl:stylesheet>