-1

Suppose I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="pathto/xsd/meta.xsd">
    <baar name="metaName"></baar>
</foo>

How to add attribute visible="false" to the node <baar>?

I tried the following:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xchange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="pathto/xsd/xchange.xsd" location="@super">     
    <insert xpath="/foo/baar/@visible" visible="false">  
    </insert>  
</xchange>

But it does not work.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
user1167753
  • 705
  • 3
  • 7
  • 15

1 Answers1

0

you can do it with XSLT

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/foo/baar">
        <baar visible="false">
            <xsl:apply-templates select="@*|node()"/>
        </baar>
    </xsl:template>
</xsl:stylesheet>

Here is the explanation adding attribute to the node

Community
  • 1
  • 1
  • hmmm in the project, is exchange / xpath is using and not xslt – user1167753 Feb 02 '16 at 12:34
  • As @kjhughes says, you should explain what xchange is. XPath is a syntax to refer to elements in a XML document and does not manipulate XML. –  Feb 02 '16 at 14:06