This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: attribute vs { }


Hello Jian,

both versions are correct, the second (so called "attribute value template")
is obviously shorter and mostly more readable. In some situations you need
the longer version.

Example 1: attribute only when condition is true

<test>
    <xsl:if test="$color != 'black'">
        <xsl:attribute name="color"><xsl:value-of
select="$color"/></xsl:attribute>
    </xsl:if>
</test>

Example 2: attribute value comes from another template

<xsl:template match="/"
    <test>
        <xsl:attribute name="color">
            <xsl:apply-templates select="color"/>
        </xsl:attribute>
    </test>
</xsl:template>

<xsl:template match="color">
    <xsl:value-of select="."/>
</xsl:template>

This is a trivial example, but the second template could be much more
complex or even a recursive template.

So, in the most cases I would use the shorter AVT. Sometimes, if it
necessary, I have to use <xsl:attribute/>.

Regards,

Joerg

> <a>
> <xsl:attribute name="href">
>   <xsl:text>file://</xsl:text>
>   <xsl:value-of select="element">
> </xsl:attribute>
> </a>
>
> and
>
> <a href="file://{element}">
>
> generate the same result with xalan.
> is it allright to use it this way?
>
> jian


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]