Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy with replace

Status
Not open for further replies.

Crisps

Programmer
Sep 28, 2006
26
US
Hi I am trying to do something that I at least think is really simple with xsl.

I have these files

Template.xml

Code:
<root>
      <data1>Hello</data1>
      <data2>World</data2>
      <spare1>Some Data</spare1>
</root>

Input.xml

Code:
<root>
    <level2>
      <input1>ajlsa</input1>
      <data1>Goodbye</data1>
      <data2>Space</data2>
    </level2>
</root>

I am trying to write a stylesheet which takes input.xml as an input and then creates an output xml that looks exactly like template.xml except with the two data fields replaced with those from input.xml

any idea of how to go about this. It is easy to save a copy of the good data from Input xml and make a copy of the Template.xml but I cannot work out how then to change the data in the output.

Expected output

Code:
<root>
      <data1>GoodBye</data1>
      <data2>Space</data2>
      <spare1>Some Data</spare1>
</root>

Thanks,

 
First, how knowledgable about XSL are you? If this is your beginning exercise, it is a somewhat unusual first project.

Also, do I understand the requirement that this requires the replacement of the data for the two elements named exactly <data1> and <data2>? Or is there a more generic requirement that, for each leaf element in template.xml for which there exists a corresponding leaf element in input.xml, replace the text node associated with that leaf element in template.xml with the data in the text node of the corresponding leaf element in input.xml?

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top