Read and Write to a XML file using XSLT -


i'm trying read file file path in xml , write contents in file new xml using xslt assuming files in same folder.

the requirement is, open , read input.xml , find file path in "filepath" tag , open , read addressbook01.xml in "filepath" , read "name" tag in addressbook01.xml file , write them in file name01.xml.

basically if sufficient know how read , write files using xslt.

is possible? i'm new , appreciated.

input xml in input.xml

?xml version="1.0" encoding="utf-8"?> <addressfiles>    <addressfile>       <name>adressbook01</name>       <filepath>addressbook01.xml</filepath>    </addressfile> <addressfiles> 

contents in addressbook01.xml

?xml version="1.0" encoding="utf-8"?> <contactdetails>     <contact>        <name>tom</name>        <address>toms address</address>     </contact>     <contact>         <name>peter</name>         <address>peters address</address>     </contact> </contactdetails> 

expected output in names01.xml

?xml version="1.0" encoding="utf-8"?> <name>tom</name> <name>peter</name> 

using xslt 2.0 processor can read in file doc function , create result document using xsl:result-document e.g.

<xsl:template match="addressfile">   <xsl:result-document href="names{replace(name, '[^0-9]+', '')}.xml">     <xsl:copy-of select="doc(filepath)//contact/name"/>   </xsl:result-document> </xsl:template> 

note expected output lacks root element containing name elements not well-formed xml document. possible create result format , suggestion in cases better create well-formed xml documents otherwise there few ways read/process created file xml tools.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -