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

2
  • See stackoverflow.com/questions/4824843/… Commented Feb 2, 2016 at 12:08
  • 2
    You should state what xchange is because it's not well-known, and XPath alone does not manipulate XML; it selects from XML. Commented Feb 2, 2016 at 12:46

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

hmmm in the project, is exchange / xpath is using and not xslt
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.

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.