Search code examples
xsltapply-templates

How can I execute an apply-templates on all non-selected attributes within a xsl:copy?


Let's say I have the following XSLT:

<xsl:template match="property">
    <xsl:copy>
        <xsl:apply-templates select="@id"/>
        <xsl:apply-templates select="@name"/>
        <xsl:apply-templates select="@componentClassID"/>
    </xsl:copy>
  </xsl:template>

How can I conclude the copy with an apply-templates statement that selects all attributes not specified in the previous apply-templates statements?

Would the following be correct?

<xsl:apply-templates select="@*[name()!='id' and name()!='name' and name()!='componentClassID']"/>

Solution

  • Would the following be correct?

    <xsl:apply-templates select=
     "@*[name()!='id' and name()!='name' and name()!='componentClassID']"/>
    

    Yes, but it seems too-long. Also, it is recommended never to use the != operator, because of its unintuitive semantics (behavior) when one of its arguments is a node-set.

    When there are many attribute names to be excluded, I'd rather write in the following style:

    <xsl:apply-templates select=
     "@*[not(contains('+id+name+componentClassID+', concat('+', name(), '+')))]"/>