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:call-template name="type"/> 15 <xsl:apply-templates select="*[local-name() != 'type']"/> 16 </xsl:copy> 17 </xsl:template> 18 19 <!-- Investigate type elements. --> 20 21 <xsl:template name="type"> 22 <!-- Make the element. --> 23 <type> 24 <xsl:apply-templates select="type/@*"/> 25 <xsl:call-template name="type-enum"/> 26 </type> 27 </xsl:template> 28 29 <!-- Add to type elements the range of acceptable values. --> 30 31 <xsl:template name="type-enum"> 32 <!-- Find all values in the range and add them. --> 33 <xsl:for-each select="$types/types/type-enum"> 34 <xsl:copy> 35 <xsl:apply-templates select="@*"/> 36 </xsl:copy> 37 </xsl:for-each> 38 </xsl:template> 39 40 <!-- Replicate unknown elements. --> 41 42 <xsl:template match="@*|*|node()"> 43 <xsl:copy> 44 <xsl:apply-templates select="@*|*|node()"/> 45 </xsl:copy> 46 </xsl:template> 47 48 </xsl:stylesheet>