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"?>
<lib>
  
  <book>
  <name>Modern Operating System</name>
  <author>Andrew S. Tanenbaum</author>
  <edition>3rd Edition</edition>
  <price>1500</price>
  <ISBN>978-81-203-3904-1</ISBN>
  </book>
  
  <book>
  <name>PHP and MySQL Web Development</name>
  <author>Luke Welling and Laura Thomson</author>
  <edition>4th Edition</edition>
  <price>1200</price>
  <ISBN>672-32672-8</ISBN>
  </book>
  
  <book>
  <name>Rapid Development- Taming Wild Software Assessment Schedules</name>
  <author>Steve McConnell</author>
  <edition>5th Edition</edition>
  <price>1000</price>
  <ISBN>1-55615-900-5</ISBN>
  </book>

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

<book>
  <name>SAMs Teach Yourself UML in 24 Hours</name>
  <author>Joseph Schmuller</author>
  <edition>3rd Edition</edition>
  <price>1580</price>
  <ISBN>81-297-0609-1</ISBN>
  </book>
  
  <book>
  <name>System Analysis and METHODS</name>
  <author>Jeffrey L Whitten and Lonnie D Bentley</author>
  <edition>7th Edition</edition>
  <price>1800</price>
  <ISBN>0-07-063417-3</ISBN>
  </book>
  
  </lib>
<!-- 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="/">

<html>
<body>
<h1>Library System</h1>
<table border="1.0" bordercolor="#0066FF">
<tr bgcolor="#33CCCC">
<th>Book Name</th>
<th>Author</th>
<th>Edition</th>
<th>Price(Rs.)</th>
<th>ISBN</th>
</tr>

<xsl:for-each select="lib/book">
<tr>
<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>
</tr>
 </xsl:for-each>
 </table>
 </body>
 </html>
 </xsl:template>
 </xsl:stylesheet>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.