RE: [xsl] Conditionally use attribute sets?

Subject: RE: [xsl] Conditionally use attribute sets?
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Mon, 14 Nov 2005 12:07:24 +0200
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

Current Thread