Welcome to WebmasterWorld Guest from 54.162.155.183

Forum Moderators: httpwebwitch

Message Too Old, No Replies

XSLT to convert 2 XML files to 1

     
7:01 pm on Oct 7, 2008 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



It's been years since I've done any XSLT work. Any help appreciated.

I have an XML file that resembles something like this:

<Node> 
<LocationBase url="http://example.com/foo/" />
<Node>
<Item>
<Id>12345</Id>
</Item>
<Item>
<Id>98765</Id>
</Item>
</Node>
</Node>

Each Item represents another XML file located at LocationBase. For example:

http://example.com/foo/12345.xml
and
http://example.com/foo/98765.xml

Those files might look like this:

<folder> 
<list>
<record />
<record />
</list>
<folder>
<list>
<record />
</list>
</folder>
</folder>

Note, in the first example there could be any number of nested Nodes, and in this example there could be any number of nested folders.

Is there a way to combine these (with XLST) into a single structure like this:

<Node> 
<LocationBase url="http://example.com/foo/" />
<Node>
<Item>
<folder>
<list>
<record />
<record />
</list>
<folder>
<list>
<record />
</list>
</folder>
</folder>
</Item>
<Item>
<folder>
...
</folder>
</Item>
</Node>
</Node>

Any input appreciated.

12:43 am on Oct 8, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



you'll probably need to employ an unusual feature of XSLT2: the document() function which lets you specify a whole external XML file as though it's the current node

reference:
[w3.org...]

example:
<xsl:variable name="doc2" select="document('/foo/12345.xml')" />

1:23 pm on Oct 8, 2008 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Interesting. Thanks! :-)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month