[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: name of a template

Subject: Re: name of a template
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Jan 2001 16:17:51 +0000
attribute block 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.