This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: REQUIRED vs. IMPLIED attributes
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: REQUIRED vs. IMPLIED attributes
- From: "Nikolai Grigoriev" <grig at renderx dot com>
- Date: Sun, 23 Jul 2000 11:30:17 +0400
- References: <3.0.1.32.20000722104231.0095ba30@localhost>
- Reply-To: xsl-list at mulberrytech dot com
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