This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: attribute vs { }
- From: "Joerg Heinicke" <joerg dot heinicke at gmx dot de>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 27 Mar 2002 08:52:19 +0100
- Subject: Re: [xsl] attribute vs { }
- References: <F48adlArlhrB60IalDI0000bf4d@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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