xsl-list
[Top] [All Lists]

RE: list of actual attributes?

2005-04-08 04:04:24
I use separate templates for those elements and attributes I 
need to change and for
the rest I use the following:

<xsl:template match="*">
        <xsl:element name="{name()}">
        <xsl:for-each select="@*">
        <xsl:attribute name="{name()}">
        <xsl:apply-templates select="."/>
        </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates/>
        </xsl:element>
</xsl:template>

This is a home-grown version of the identity template that has a number of
disadvantages compared with the usual versions.

Using xsl:element rather than xsl:copy loses namespace nodes.

Using xsl:apply-templates within xsl:attribute seems a poor compromise.
Either you should copy over the attributes unchanged using <xsl:copy-of
select="@*"/> (in which case you need to supply an overriding template for
the containing element if you want different behavior), or you should apply
templates to all the attributes using <xsl:apply-templates select="@*"/>
(and create the attribute node in the called template), so for example if
you want to drop or rename one particular attribute you can write a template
rule to do that.

I generally use

<xsl:template match="*">
<xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
</xsl:template>


Anyway, the problem I'm experiencing is - the list of 
attributes that I get using '@*' seems to
also include the attributes with default values from the DTD. 

The XML parser expands the list of attributes, there's nothing you can do
about this other than to change the DTD.

Michael Kay
http://www.saxonica.com/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>