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 <!-- Add or process comment elements inside item elements. --> 6 <!-- This transformation must happen after type elements have been populated. --> 7 8 <xsl:template match="item"> 9 <!-- Copy the element and its contents. --> 10 <xsl:copy> 11 <xsl:apply-templates select="@*"/> 12 <!-- Ensure an options element. --> 13 <xsl:call-template name="options"/> 14 <xsl:apply-templates select="*[local-name() != 'options']"/> 15 </xsl:copy> 16 </xsl:template> 17 18 <!-- Investigate options elements. --> 19 20 <xsl:template name="options"> 21 <!-- Make the element. --> 22 <options> 23 <!-- Only for certain element types... --> 24 <xsl:if test="type/type-enum[@value='P' and @value-is-set]"> 25 <!-- Add comments. --> 26 <comment> 27 <xsl:apply-templates select="options/comment/@value"/> 28 </comment> 29 </xsl:if> 30 </options> 31 </xsl:template> 32 33 <!-- Replicate unknown elements. --> 34 35 <xsl:template match="@*|*|node()"> 36 <xsl:copy> 37 <xsl:apply-templates select="@*|*|node()"/> 38 </xsl:copy> 39 </xsl:template> 40 41 </xsl:stylesheet>