0

I am trying to transform single attribute to an element. The XSL I use is :

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

my xml:

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

The above XSL transforms all the attributes to elements. But I want to transform only the 'custom:attribute' and ignore the others. How can I achieve this? Thanks in advance.

1 Answer 1

3

Replaced @* with @custom:attribute
Therefore try:

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

But attention: custom is a namespace prefix. You have to add it with the same namespace URL as in your XML to your xsl:stylesheet. Something like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:custom="CUSTOM_URL"
    version="1.0">
Sign up to request clarification or add additional context in comments.

3 Comments

hr_117 Thank you..But even the other attributes are displayed..how can I remove everything except for custom:attribute ???
I assume you have a identity transfer template in your xslt. Therefore ads a new template to ignore attributes of TextView (<xsl:template match="TextView/@*" />)
@hr_117 note that you'll need to add explicit priority="..." to both templates, as TextView/@custom:attribute and TextView/@* have the same priority by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.