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