What is an XSLT (version 1.0) transform that can add or replace property values based on name?
For example, given the following input XML
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/hadoop/dfs/name</value>
</property>
</configuration>
How would I specify two properties with names and values, for example:
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/hadoop/dfs/data</value>
</property>
</configuration>
So the resulting XML contains all original children of the root configuration
element, and only one property
with a given name
? For example:
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/hadoop/dfs/data</value>
</property>
</configuration>
I've tried exampled from several other questions, but they don't have the same schema, and I don't know enough XSLT to adjust to my use case.
Given:
Input XML
override.xml
the following stylesheet:
XSLT 1.0
will return:
This is a non-answer for the question, but I am posting here as a resolution for the community to the problem I was trying to solve.
I was attempting to create minimally dependent shell scripts that could update a config from a Vagrantfile.
This answer does not address the original question, so I won't accept it, but it is what I wound up going with in the meantime.
Under a
provision
directory, I created the following structure:Where
core-site.xml
looks like:hdfs-site.xml
looks similar (bare formatting),And
Override.pm
is the following:With
hadoop-config.pl
left as such: