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