如何不复制一些属性? [英] How not to copy some attributes?

查看:29
本文介绍了如何不复制一些属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有属性从输入文档复制到输出文档,但只有一个属性.

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

我的输入是这样的:

<mylink id="nextButton" type="next" href="javascript:;" />

我需要这样的输出:

<a id="nextButton" href="javascript:;" />

如果我使用以下 XSL:

If I use the following XSL:

<xsl:template match="mylink">
    <a><xsl:copy-of select="attribute::*"/></a>
</xsl:template>

我将所有属性输出如下:

I get all attributes to output like this:

<a id="nextButton" type="next" href="javascript:;" />

但我想忽略类型"属性.我尝试了以下方法,但似乎没有一个能按我需要的方式工作:

But I want to ignore the "type" attribute. I've tried the following but none of them seems to work the way I need:

<xsl:copy-of select="attribute::!type"/>
<xsl:copy-of select="attribute::!'type'"/>
<xsl:copy-of select="attribute::*[!type]"/>
<xsl:copy-of select="attribute::not(type)"/>

我应该如何编写样式表以获得所需的输出?

How should I write my stylesheet to get needed output?

推荐答案

最短形式:

<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>

这篇关于如何不复制一些属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆