[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: name of a template
Hi Carmelo, > Can the name of an attribute set be made on the fly? Briefly, no. In fact, you always know the names of the attribute sets you're using, so you can always create an xsl:choose to do it: <xsl:choose> <xsl:when test="position() = 1"> <fo:block xsl:use-attribute-sets="property1"> <xsl:value-of select="." /> </fo:block> </xsl:when> <xsl:when test="position() = 2"> <fo:block xsl:use-attribute-sets="property2"> <xsl:value-of select="." /> </fo:block> </xsl:when> ... </xsl:choose> That is *really* tedious because you have to use xsl:use-attribute-sets on the element you're creating, which means you have to create each element within the xsl:whens. It's probable, though, that your attribute sets share some attributes, perhaps with different values. This being the case, you can determine the value of the attribute based on the current node when you create the fo:block within the attribute set: <xsl:attribute-set name="shared-properties"> <xsl:attribute name="background-color"> <xsl:choose> <xsl:when test="position() = 1">white</xsl:when> <xsl:when test="position() = 2">grey</xsl:when> ... </xsl:choose> </xsl:attribute> <!-- other shared properties --> </xsl:attribute-set> and then: <fo:block xsl:use-attribute-sets="shared-properties"> <xsl:value-of select="."> </fo:block> If the different attribute sets have some different attributes, then you have to add those attributes individually: <fo:block xsl:use-attribute-sets="common-properties"> <xsl:choose> <xsl:when test="position() = 1"> <!-- property 1 attributes --> </xsl:when> <xsl:when test="position() = 2"> <!-- property 2 attributes --> </xsl:when> ... </xsl:choose> <xsl:value-of select="." /> </fo:block> If you're having to do this a lot, in different places within the stylesheet, then it's probably worth separating it out as a moded or named template: <xsl:template match="*" mode="add-properties"> <xsl:choose> <xsl:when test="position() = 1"> <!-- property 1 attributes --> </xsl:when> <xsl:when test="position() = 2"> <!-- property 2 attributes --> </xsl:when> ... </xsl:choose> </xsl:template> and then calling/applying it: <fo:block xsl:use-attribute-sets="common-properties"> <xsl:apply-template select="." mode="add-properties" /> <xsl:value-of select="." /> </fo:block> You're right though to try it: it would be nice if xsl:use-attribute-sets *could* use an attribute value template. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|