xsl-list
[Top] [All Lists]

RE: Copy Attribute Unless

2005-03-25 11:41:20
    The following works in Saxon 8.0. I assumed it was bad news to
    specify an attribute twice, but I suppose the last attribute
    node copied wins.

    <xsl:template match="control">
      <xsl:variable name="definition"
                    select="ancestor::bench/fixture/control-point[
                                          @name = current()/@name]"/>
      <xsl:copy>
        <xsl:copy-of select="$definition/@*"/>
        <xsl:copy-of select="@*"/>
      </xsl:copy>

    </xsl:template>

Yes, XSLT 2.0 (and 1.0 for that matter) specifies that you can add two
attributes with the same name to an element, and the last one wins. It's
safe to rely on this - this is standard behavior, not one of those
"recoverable errors" where some processors will report an error and others
recover from it.

You can combine the two xsl:copy-of instructions into <xsl:copy-of
select="$definition/@*, @*"/>

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>