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

Invalid entry code in python my code is pasted below. The last elif statement, I'm trying...
Invalid entry code in python my code is pasted below. The last elif statement, I'm trying to get the program to print "invalid entry" if the entry for user_input is invalid. The first user prompt should only allow for numbers 1-10 and "exit" and "quit" import math user_prompt = """Enter number of operation that you want to execute <type exit or quit to end program>: 1 sin(x) 2 cos(x) 3 tan(x) 4 asin(x) 5 acos(x) 6 atan(x) 7 ln(x) 8...
I'm trying to get my code to loop back to let the user input multiple patients....
I'm trying to get my code to loop back to let the user input multiple patients. import java.util.Scanner; public class XYZ {    public static void main(String[] args) {           String response;        do{            //import scanner for input            Scanner input = new Scanner(System.in);               //prompt user input for last name            System.out.print("Enter last name ");            //output for last name            String...
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 having a bit of an issue with one of my C++ labs. It's not for...
I'm having a bit of an issue with one of my C++ labs. It's not for score but I need to understand it so I can move on. A restaurant servers burgers for $8 and salads for $7. When the customer selects a burger they must choose if they would like cheese. If they do, cheddar costs an additional 25 cents while pepper jack is 50 cents. When the customer selects a salad they must choose if they would like...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
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())
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...
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...
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....
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:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT