R
R
Ramil2016-12-16 09:44:23
XSL & XSLT
Ramil, 2016-12-16 09:44:23

How to remove an attribute in XSL?

Hi all!
Is it possible to remove an attribute in XSL, if so, how?
I did not find it on the Internet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2018-11-04
@Roman-Fov

It would be better not to add it.
You can remove its value, for example:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output encoding="utf-8" version="1.0"/>
  <xsl:template match="/">
            <div data-attr="data-value">
                <xsl:attribute name="data-attr"/>
                <p>test</p>
            </div>
        </xsl:template>
</xsl:stylesheet>

Result:
But it is not clear why such a perversion is needed. You can also add an attribute under certain conditions (instead of removing it under the opposite conditions)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output encoding="utf-8" version="1.0"/>
  <xsl:template match="/">
            <div>
                <xsl:if test="true()">
                    <xsl:attribute name="data-attr">value</xsl:attribute>
                </xsl:if>
                <p>test</p>
            </div>
            <div>
                <xsl:if test="false()">
                    <xsl:attribute name="data-attr">value</xsl:attribute>
                </xsl:if>
                <p>test</p>
            </div>
        </xsl:template>
</xsl:stylesheet>

result:
<div data-attr="value"><p>test</p></div>
<div><p>test</p></div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question