Question

In: Computer Science

XML and XSL I'm trying to style my XML code but it's not implementing the XSL...

XML and XSL

I'm trying to style my XML code but it's not implementing the XSL file when I run it even though the file is referenced. Any help?

XML code:

<?xml version="1.0"?>
<?xml-stylesheet href="textbooks.xsl" type="text/xsl" ?>
<textbooks>
<textbook>
<title> Introduction to Design and Analysis of Algorithms</title>
<authors>
<author>
<firstName>Anany</firstName>
<lastName>Levitin</lastName>
</author>
</authors>
<publisher>
<name>Ed, Pearson</name>
<website>https://www.pearson.com</website>
</publisher>
<Year-of-Publication>2011</Year-of-Publication>
<ISBN>978-0132316811</ISBN>
<book-specific-website></book-specific-website>
<edition>3rd edition</edition>
<cover-type>Paperback</cover-type>
</textbook>

<textbook>
<title>Software Engineering: A Practitioner’s Approach</title>
<authors>
<author>
<firstName>Roger</firstName>
<lastName>Pressman</lastName>
</author>
</authors>
<publisher>
<name>Ed, McGraw-Hill</name>
<website>www.mheducation.com</website>
</publisher>
<Year-of-Publication>2014</Year-of-Publication>
<ISBN>8126554274</ISBN>
<book-specific-website></book-specific-website>
<edition>8th edition</edition>
<cover-type>Hardcover</cover-type>
</textbook>

<textbook>
<title>Internet and World Wide Web: How to Program with CD-ROM BK and CD ROM</title>
<authors>
<author>
<firstName>Harvey</firstName>
<lastName>Deitel</lastName>
</author>
</authors>
<publisher>
<name>Prentice Hall,</name>
<website>https://www.amazon.com/Internet-World-Wide-Web-Program/dp/0131450913</website>
</publisher>
<Year-of-Publication>2004</Year-of-Publication>
<ISBN> 0131450913</ISBN>
<book-specific-website></book-specific-website>
<edition>3rd edition</edition>
<cover-type>Hardcover</cover-type>
</textbook>
</textbooks>

XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/textbooks">
<html>
<body>
<table border="1">
<tr>
   <th>Title</th>
   <th>Author First Name</th>
   <th>Author Last Name</th>
   <th>Publisher Name</th>
   <th>Publisher website</th>
   <th>Year of publication</th>
   <th>ISBN</th>
   <th>Book Website</th>
   <th>Edition</th>
   <th>Cover Type</th>
   </tr>
  
   <xsl:for-each select="textbook">
   <tr>
   <td><xsl:value-of select="title"/></td>
   <td><xsl:value-of select="authors/firstName"/></td>
   <td><xsl:value-of select="authors/lastName"/></td>
   <td><xsl:value-of select="publisher/name"/></td>
   <td><xsl:value-of select="publisher/website"/></td>
   <td><xsl:value-of select="Year-of-publication"/></td>
   <td><xsl:value-of select="ISBN"/></td>
   <td><xsl:value-of select="book-specific-website"/></td>
   <td><xsl:value-of select="edition"/></td>
   <td><xsl:value-of select="cover-type"/></td>
   <tr>
   <xsl:for-each>
   <table>     
</body>
</html>

Solutions

Expert Solution

Error details :

  • Changed this line <xsl:template match="/textbooks"> to <xsl:template match="/">
  • author first name and last name in the <authors><author><firstName> hence in the xsl used like <td><xsl:value-of select="authors/author/firstName"/></td>
  • Closing of some tag was missing like </xsl:template> and </xsl:stylesheet> etc.
  • Also note the run the xml file from any server like localhost then only xsl file will be applied to xml

****************************************

textbooks.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>

<table border="1">

<tr>

   <th>Title</th>

   <th>Author First Name</th>

   <th>Author Last Name</th>

   <th>Publisher Name</th>

   <th>Publisher website</th>

   <th>Year of publication</th>

   <th>ISBN</th>

   <th>Book Website</th>

   <th>Edition</th>

   <th>Cover Type</th>

   </tr>

  

   <xsl:for-each select="textbooks/textbook">

   <tr>

   <td><xsl:value-of select="title"/></td>

   <td><xsl:value-of select="authors/author/firstName"/></td>

   <td><xsl:value-of select="authors/author/lastName"/></td>

   <td><xsl:value-of select="publisher/name"/></td>

   <td><xsl:value-of select="publisher/website"/></td>

   <td><xsl:value-of select="Year-of-publication"/></td>

   <td><xsl:value-of select="ISBN"/></td>

   <td><xsl:value-of select="book-specific-website"/></td>

   <td><xsl:value-of select="edition"/></td>

   <td><xsl:value-of select="cover-type"/></td>

   </tr>

   </xsl:for-each>

   </table>     

</body>

</html>

</xsl:template>

</xsl:stylesheet>

***************************************************

textbooks.xml :

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl"  href="textbooks.xsl" ?>

<textbooks>

<textbook>

<title> Introduction to Design and Analysis of Algorithms</title>

<authors>

<author>

<firstName>Anany</firstName>

<lastName>Levitin</lastName>

</author>

</authors>

<publisher>

<name>Ed, Pearson</name>

<website>https://www.pearson.com</website>

</publisher>

<Year-of-Publication>2011</Year-of-Publication>

<ISBN>978-0132316811</ISBN>

<book-specific-website></book-specific-website>

<edition>3rd edition</edition>

<cover-type>Paperback</cover-type>

</textbook>

<textbook>

<title>Software Engineering: A Practitioner’s Approach</title>

<authors>

<author>

<firstName>Roger</firstName>

<lastName>Pressman</lastName>

</author>

</authors>

<publisher>

<name>Ed, McGraw-Hill</name>

<website>www.mheducation.com</website>

</publisher>

<Year-of-Publication>2014</Year-of-Publication>

<ISBN>8126554274</ISBN>

<book-specific-website></book-specific-website>

<edition>8th edition</edition>

<cover-type>Hardcover</cover-type>

</textbook>

<textbook>

<title>Internet and World Wide Web: How to Program with CD-ROM BK and CD ROM</title>

<authors>

<author>

<firstName>Harvey</firstName>

<lastName>Deitel</lastName>

</author>

</authors>

<publisher>

<name>Prentice Hall,</name>

<website>https://www.amazon.com/Internet-World-Wide-Web-Program/dp/0131450913</website>

</publisher>

<Year-of-Publication>2004</Year-of-Publication>

<ISBN> 0131450913</ISBN>

<book-specific-website></book-specific-website>

<edition>3rd edition</edition>

<cover-type>Hardcover</cover-type>

</textbook>

</textbooks>

=================================================

Output :


Related Solutions

I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone....
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone. Make this subclass have a no-arg constructor and a constructor that takes a name, email, and phone. Override the toString method to return the required output. Given Files: public class Demo1 { public static void test(Phone p) { System.out.println("Getter test:"); System.out.println(p.getName()); System.out.println(p.getNumber()); } public static void main(String[] args) { Phone test1 = new SmartPhone(); Phone test2 = new SmartPhone("Alice", "8059226966", "[email protected]"); System.out.println(test1); System.out.println(test2); System.out.println(test1);...
I'm writing a code for the Secant Method for root finding, but my code makes an...
I'm writing a code for the Secant Method for root finding, but my code makes an infinite code of the correct answer. Below is my code, how do I fix it? def f(x): return (x**6)+7*(x**5)-15*(x**4)-70*(x**3)+75*(x**2)+175*x-125 def secant(): p0=float(input('Enter an initial guess for the root ')) p1=float(input('Enter another guess ')) TOL=float(input('Enter a tolerance in decimal form ')) n=15 i=1 while i<=n: p=p1-f(p1)*(p1-p0)/(f(p1)-f(p0)) if abs(p-p1)<TOL: print(p) else: p0=p1 p1=p i=i+1 else: print(p) return p    print(secant())
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
The source code I have is what i'm trying to fix for the assignment at the...
The source code I have is what i'm trying to fix for the assignment at the bottom. Source Code: #include <iostream> #include <cstdlib> #include <ctime> #include <iomanip> using namespace std; const int NUM_ROWS = 10; const int NUM_COLS = 10; // Setting values in a 10 by 10 array of random integers (1 - 100) // Pre: twoDArray has been declared with row and column size of NUM_COLS // Must have constant integer NUM_COLS declared // rowSize must be less...
Hi, I'm trying to rewrite the code below (code #1) by changing delay() to millis(). void...
Hi, I'm trying to rewrite the code below (code #1) by changing delay() to millis(). void loop() { // Print the value inside of myBPM. Serial.begin(9600); int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int". // "myBPM" hold this BPM value now. if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened". Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened". Serial.print("BPM:...
***The code is provided below*** When trying to compile the code below, I'm receiving three errors....
***The code is provided below*** When trying to compile the code below, I'm receiving three errors. Can I get some assistance on correcting the issues? I removed the code because I thought I corrected my problem. I used #define to get rid of the CRT errors, and included an int at main(). The code compiles but still does not run properly. When entering the insertion prompt for the call details, after entering the phone number, the program just continuously runs,...
I'm trying to decide if I want to invest in a refinery to upgrade my bitumen...
I'm trying to decide if I want to invest in a refinery to upgrade my bitumen to oil. Currently it costs me $40, to get my bitumen to market, where I am able to sell it for $50 a barrel. If I decided to upgrade, it will costs me an extra $6 a barrel, these will produce 30 liters of oil, which I can sell for $2 each.   Should I expand my business? Select one: a. Yes - 4 b....
I'm trying to space out my 3 inputs when they are displayed in the list box....
I'm trying to space out my 3 inputs when they are displayed in the list box. I've tried putting "\t" and "" in between inputs and it makes the 3rd input not visible, I've tried expanding my listbox and it still wasn't visible either. private void button2_Click(object sender, EventArgs e) { //clear any previous values listBox3.Items.Clear(); for (int index = 0; index < currentCapacity; index++) { listBox3.Items.Add(string.Format("{0, -10}{1, 10}{2, 10}", name[index],numTickets[index],costs[index].ToString("C"))); } }
im trying to write a java code that take a matrix of vector and fine it's...
im trying to write a java code that take a matrix of vector and fine it's inverse (the the inverse in linear algebra) then multiple this matrix with a vector to fine other vector (matrix)-1 × ( vector ) = (vector)
Hello! I'm trying to write a code that will either encrypt/decrypt a message from an inputed...
Hello! I'm trying to write a code that will either encrypt/decrypt a message from an inputed text. I'm having the absolute hardest time getting stared and figuring out how to identify in the code if the input needs to be encrypted/decrypted and identifying the string to encrypt/decrypt with. These are the instructions: Objectives Command line input File input and output Rethrowing exceptions Program Description Gaius Julius Caesar encoded his battle messages so that the opponent could not read them should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT