How not to copy some attributes?

前端 未结 2 1776
不知归路
不知归路 2021-01-07 17:43

I need to copy from input document to output document all attributes but one.

My input is like this:



        
相关标签:
2条回答
  • 2021-01-07 18:18

    Shortest form:

    <xsl:template match="mylink">
        <a><xsl:copy-of select="@*[name()!='type']"/></a>
    </xsl:template>
    

    Longer one (that's the first thing I came up with, I leave it for reference):

    <xsl:template match="mylink">
        <a>
         <xsl:for-each select="@*">
          <xsl:if test="name() != 'type'">
           <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
          </xsl:if> 
         </xsl:for-each>
        </a>
    </xsl:template>
    
    0 讨论(0)
  • 2021-01-07 18:26

    In XSLT 2.0:

    <xsl:template match="mylink">
      <a><xsl:copy-of select="@* except @type"/></a>
    </xsl:template>
    
    0 讨论(0)
提交回复
热议问题