0

我正在尝试将单个属性转换为元素。我使用的 XSL 是:

   <xsl:template match="TextView/@*">
   <xsl:element name="{name()}">
   <xsl:value-of select="."/>
   </xsl:element>
   </xsl:template>

我的xml:

    <TextView
     android:id="@+id/ti"
     style="@style/HTxt"
     android:text="@string/ti"
     custom:attribute="name" />

上面的 XSL 将所有属性转换为元素。但我只想转换“custom:attribute”而忽略其他的。我怎样才能做到这一点?提前致谢。

4

1 回答 1

3

替换@*@custom:attribute
因此尝试:

<xsl:template match="TextView/@custom:attribute">
        <xsl:element name="{name()}">
            <xsl:value-of select="."/>
        </xsl:element>
</xsl:template>

但注意custom命名空间前缀。您必须使用与 XML 中相同的命名空间 URL 将其添加到 xsl:stylesheet。就像是:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:custom="CUSTOM_URL"
    version="1.0">
于 2013-06-21T10:04:11.013 回答