xsl-list
[Top] [All Lists]

RE: Conditionally use attribute sets?

2005-11-14 03:07:24
Hi, 

 I'd like to conditionally add an attribute set to an 
element.  Something like this:

You're not the only one :/

   <xsl:attribute-set name="my.set">
     <xsl:attribute name="attr">value</xsl:attribute>
   </xsl:attribute-set>

   <literal-res-elem>
     <xsl:if test="@condition">
       <xsl:use-attribute-sets name="my.set"/>
     </xsl:if>
   </literal-res-elem>

 But after the recommendation, it seems it's not possible:

No, you can use xsl:choose to generate two literal result elements, one with 
the attribute set and one without. If you're into extensions, you can generate 
a dummy RLE that has the attribute set, then cast that into a node-set and then 
conditionally copy e:node-set($dummy)/*/@* but that's ugly. In some cases you 
can stick the test into the xsl:attribute, but in your case it wouldn't work as 
that way you can only control the value of the attribute, not the occurrence. 
Clearly a case where XSLT forces you to just through few hoops.

Jarno

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--