Re: [xsl] Embeding xml inside another xml using xslt

Subject: Re: [xsl] Embeding xml inside another xml using xslt
From: James Fuller <jim.fuller@xxxxxxxxxxxxxx>
Date: Mon, 28 Feb 2005 16:22:33 +0100
babu.eshwaramoorthy@xxxxxxxxx wrote:

Hi All,

Can any one help me to implement the below.

I want to form an XML which will have another XML embedded in it using
XSLT

For example I want the output to be as below

<!--- XML1 -->
<?xml version="1.0" encoding="UTF-8"?>
<note xmlns="http://www.w3schools.com"; >
	<to>Request</to>
	<from>String</from>
	<address>
<!--- 	Embeded XML2 -->
	<?xml version="1.0" encoding="UTF-8"?>
	<Address xmlns="http://www.w3schools.com"; >
		<Street>St Joseph Street</Address>
		<State>CA</State>
		<Country>US</Country>
	</Address>

</address>
<body>String</body>
</note>



hmmmm, a few things;


- u might find something here (http://www.dpawson.co.uk/xsl/sect2/N4760.html)

- btw no need for another XML PI e.g. <!xml in the body (above embed xml2), most processors will choke on such things

- you could use an xinclude style approach to including xml documents in other xml documents, though of course you then need your processor to be xinclude aware

then your xml would look like;

<?xml version="1.0" encoding="UTF-8"?>
<note xmlns="http://www.w3schools.com"; >
	<to>Request</to>
	<from>String</from>
	<address>

<xi:include href="otheraddress.xml" xmlns:xinclude="http://www.w3.org/2003/XInclude"/>

	</address>
	<body>String</body>
</note>


with the embedded xml, being a seperate document....of course u need an xinclude aware processor...xerces does it..


though if u were using the embedded document principle...you could take advantage of XSL/XPATH document() command ala

<?xml version="1.0" encoding="UTF-8"?>
<note xmlns="http://www.w3schools.com"; >
	<to>Request</to>
	<from>String</from>
	<address>

<address href="otheraddress.xml"/>

	</address>
	<body>String</body>
</note>


now you would have to supply document() with the attribute @href value.....a bit awkward though if you dont have access to an xinclude aware processor....



I wouldnt even bother with xlink etc...


gl, Jim Fuller

Current Thread