Re: REQUIRED vs. IMPLIED attributes

Subject: Re: REQUIRED vs. IMPLIED attributes
From: "Nikolai Grigoriev" <grig@xxxxxxxxxxx>
Date: Sun, 23 Jul 2000 11:30:17 +0400
Jeni Tennison wrote:

> For a more generic solution, you can cycle through the attributes that are
> present and make copies of them.  Naturally, this will capture all
> #REQUIRED attributes (as they will be [*must* be] present) and any #IMPLIED
> attributes that are around.

> The problem with this approach is that you cannot change the names of the
> attributes.  This involves using extra knowledge about the mapping between
> the old names and the new names, which you have to either embed in the
> template itself or make explicit elsewhere and reference from within the
> template (let me know if you want to see an example).

In such cases, it may be convenient to delegate attribute processing to separate
templates, instead of a for-each loop. This is more verbose, but (IMHO) it
yields a better manageable code:

<xsl:template match="Link">
    <h2><xsl:apply-templates select="@*|text()"/></h2>
</xsl:template>

<!-- A default rule for processing link attributes -->
<xsl:template match="Link/@*" priority="-1">
    <xsl:copy/>
</xsl:template>

<!-- To change a name of an attribute -->
<xsl:template match="Link/@linkid">
    <xsl:attribute name="name">
        <xsl:value-of select="."/>
    </xsl:attribute>
</xsl:template>

<!-- To prevent an attribute from being copied -->
<xsl:template match="Link/@unused-attribute"/>

<!-- etc. etc. ;-) -->

Regards,

Nikolai Grigoriev
RenderX



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


Current Thread