Skip to main content
added 328 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

If you need to match the exact values of the attributes in the node, then do so with a more specific XPath query in the match of the second template:

<xsl:template match="/Context/Valve[ @className='org.apache.catalina.valves.RemoteAddrValve' and @allow='127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1' ]"> 

Applying it can be done with xmlstarlet tr transform.xsl file.xml or with xsltproc transform.xsl file.xml:

Applying it can be done with xmlstarlet tr transform.xsl file.xml or with xsltproc transform.xsl file.xml:

If you need to match the exact values of the attributes in the node, then do so with a more specific XPath query in the match of the second template:

<xsl:template match="/Context/Valve[ @className='org.apache.catalina.valves.RemoteAddrValve' and @allow='127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1' ]"> 

Applying it can be done with xmlstarlet tr transform.xsl file.xml or with xsltproc transform.xsl file.xml:

added 98 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Using xsltproc or xmlstarlet with an XSL transformation in transform.xsl:

<?xml version="1.0"?> <xsl:stylesheettransform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/|node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/Context/Valve"> <xsl:text disable-output-escaping="yes">&lt;!-- </xsl:text> <xsl:copy-of select="."/> <xsl:text disable-output-escaping="yes"> --&gt;</xsl:text> </xsl:template> </xsl:stylesheet>transform> 

The first template is just an identity transformation, while the second template inserts <!-- and --> around the /Context/Valve node.

Applying it can be done with xmlstarlet tr transform.xsl file.xml or with xsltproc transform.xsl file.xml:

$ xmlstarlet trxsltproc transform.xsl file.xml <?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 

This would handle commenting out the node whatever the formatting of it happens to be.

If it's a static file that won't change, then just insert the comment markup on the correct lines:

sed '17s/^/<!-- /; 18s/$/ -->/' file.xml 

Using xmlstarlet with an XSL transformation in transform.xsl:

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/|node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/Context/Valve"> <xsl:text disable-output-escaping="yes">&lt;!-- </xsl:text> <xsl:copy-of select="."/> <xsl:text disable-output-escaping="yes"> --&gt;</xsl:text> </xsl:template> </xsl:stylesheet> 

The first template is just an identity transformation, while the second template inserts <!-- and --> around the /Context/Valve node.

Applying it:

$ xmlstarlet tr transform.xsl file.xml <?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 

This would handle commenting out the node whatever the formatting of it happens to be.

If it's a static file that won't change, then just insert the comment markup on the correct lines:

sed '17s/^/<!-- /; 18s/$/ -->/' file.xml 

Using xsltproc or xmlstarlet with an XSL transformation in transform.xsl:

<?xml version="1.0"?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/|node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/Context/Valve"> <xsl:text disable-output-escaping="yes">&lt;!-- </xsl:text> <xsl:copy-of select="."/> <xsl:text disable-output-escaping="yes"> --&gt;</xsl:text> </xsl:template> </xsl:transform> 

The first template is just an identity transformation, while the second template inserts <!-- and --> around the /Context/Valve node.

Applying it can be done with xmlstarlet tr transform.xsl file.xml or with xsltproc transform.xsl file.xml:

$ xsltproc transform.xsl file.xml <?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 

This would handle commenting out the node whatever the formatting of it happens to be.

If it's a static file that won't change, then just insert the comment markup on the correct lines:

sed '17s/^/<!-- /; 18s/$/ -->/' file.xml 
edited body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Using xmlstarlet with an XSL transformation in transform.xsl:

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/|node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/Context/Valve"> <xsl:text disable-output-escaping="yes">&lt;!-- </xsl:text> <xsl:copy-of select="."/> <xsl:text disable-output-escaping="yes"> --&gt;</xsl:text> </xsl:template> </xsl:stylesheet> 

The first template is just an identity transformation, while the second template inserts <!-- and --> around the /Context/Valve node.

Applying it:

$ xmlstarlet tr transform.xsl file.xml <?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 

This would handle commenting out the node whatever the formatting of it happens to be.

If it's a static file that won't change, then just insert the commandcomment markup on the correct lines:

sed '17s/^/<!-- /; 18s/$/ -->/' file.xml 

Using xmlstarlet with an XSL transformation in transform.xsl:

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/|node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/Context/Valve"> <xsl:text disable-output-escaping="yes">&lt;!-- </xsl:text> <xsl:copy-of select="."/> <xsl:text disable-output-escaping="yes"> --&gt;</xsl:text> </xsl:template> </xsl:stylesheet> 

The first template is just an identity transformation, while the second template inserts <!-- and --> around the /Context/Valve node.

Applying it:

$ xmlstarlet tr transform.xsl file.xml <?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 

This would handle commenting out the node whatever the formatting of it happens to be.

If it's a static file that won't change, then just insert the command markup on the correct lines:

sed '17s/^/<!-- /; 18s/$/ -->/' file.xml 

Using xmlstarlet with an XSL transformation in transform.xsl:

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/|node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="/Context/Valve"> <xsl:text disable-output-escaping="yes">&lt;!-- </xsl:text> <xsl:copy-of select="."/> <xsl:text disable-output-escaping="yes"> --&gt;</xsl:text> </xsl:template> </xsl:stylesheet> 

The first template is just an identity transformation, while the second template inserts <!-- and --> around the /Context/Valve node.

Applying it:

$ xmlstarlet tr transform.xsl file.xml <?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"/> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 

This would handle commenting out the node whatever the formatting of it happens to be.

If it's a static file that won't change, then just insert the comment markup on the correct lines:

sed '17s/^/<!-- /; 18s/$/ -->/' file.xml 
added 4 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading
deleted 1 character in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading