Hi. I'm new to xml. This is my sample codes.

<!-- library1.xml -->
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="library.xsl"?>
  <name>Modern Operating System</name>
  <author>Andrew S. Tanenbaum</author>
  <edition>3rd Edition</edition>
  <name>PHP and MySQL Web Development</name>
  <author>Luke Welling and Laura Thomson</author>
  <edition>4th Edition</edition>
  <name>Rapid Development- Taming Wild Software Assessment Schedules</name>
  <author>Steve McConnell</author>
  <edition>5th Edition</edition>

<!-- library2.xml -->
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="library.xsl"?>

  <name>SAMs Teach Yourself UML in 24 Hours</name>
  <author>Joseph Schmuller</author>
  <edition>3rd Edition</edition>
  <name>System Analysis and METHODS</name>
  <author>Jeffrey L Whitten and Lonnie D Bentley</author>
  <edition>7th Edition</edition>
<!-- library.xsl -->
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<h1>Library System</h1>
<table border="1.0" bordercolor="#0066FF">
<tr bgcolor="#33CCCC">
<th>Book Name</th>

<xsl:for-each select="lib/book">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="edition"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="ISBN"/></td>

I want to get all these informations in those 2 xml files into a single table using xsl. So how do i change above xsl file to gain it. please help me to merge 2 or more xml files using xsl

There's multiple ways to do this. The best way is to use the document() function to pull your other file in as a second node set variable. Then you can process that node just like anything else.

<xsl:variable name="AnotherDocument" select="document('SomeDoc.xml')" />

Then you can access this variable just like any other node set. Or do whatever you want with it. Example.

<xsl:apply-templates select="$AnotherDocument/lib/book" />

In your case you would to process the onedocument first to create the first part of your output tree, then process the other document the same way for the second half of your output.

This article has been dead for over six months. Start a new discussion instead.