Mega Code Archive

 
Categories / XML / XSLT StyleSheet
 

Add one more attribute to group and override the value of another

File: Data.xml <poem year="1667" type="epic">   <verse>line 3</verse>   <verse>line 4</verse> </poem> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0">   <xsl:output omit-xml-declaration="yes" />   <xsl:attribute-set name="lineAttrs">     <xsl:attribute name="status">done</xsl:attribute>     <xsl:attribute name="hue">     <xsl:value-of select="@color" />   </xsl:attribute>     <xsl:attribute name="number">     <xsl:value-of select="amount" />   </xsl:attribute>     <xsl:attribute name="sourceElement">     <xsl:text>src</xsl:text><xsl:value-of select="generate-id()" />   </xsl:attribute>   </xsl:attribute-set>   <xsl:template match="verse">     <xsl:element name="line" use-attribute-sets="lineAttrs">       <xsl:attribute name="author">BD</xsl:attribute>       <xsl:attribute name="hue">NO COLOR</xsl:attribute>       <xsl:apply-templates />     </xsl:element>   </xsl:template> </xsl:stylesheet> Output:   <line status="done" hue="NO COLOR" number="" sourceElement="srcd2e3" author="BD">line 3</line>   <line status="done" hue="NO COLOR" number="" sourceElement="srcd2e6" author="BD">line 4</line>