0

I have a simple xml and xsl program to print a student data in a table and this is the first time I'm using xml. After completing the program while running the program I'm not getting the output on the table. On first I thought there is may be some errors on my code, but I tried the same xml and xsl files on three of my friends ubuntu system and it's working perfectly. For information I'm using ubuntu 18 and all of my friends are using the same. I tried the same code on the same way I did on my system on theirs, but still I'm not getting the output. Can anyone tell me why I'm having this problem.

This is my xml file(Student.xml):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Student.xsl"?>
<studInfo>
  <stud>
    <name>ABC</name>
    <dob>12/04/2020</dob>
    <rno>REG001</rno>
    <course>MCA</course>
  </stud>
  <stud>
    <name>ABC</name>
    <dob>12/04/2020</dob>
    <rno>REG001</rno>
    <course>MCA</course>
  </stud>
  <stud>
    <name>ABC</name>
    <dob>12/04/2020</dob>
    <rno>REG001</rno>
    <course>MCA</course>
  </stud>
</studInfo>

This is my xsl file(Student.xsl):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Student Details</title>
      </head>
      <body>
        <center>
          <table border="1">
            <caption>Student Details</caption>
            <tr>
              <th>Name</th>
              <th>Date of birth</th>
              <th>Register No</th>
              <th>Course</th>
            </tr>
            <xsl:for-each select="/studInfo/stud">
              <tr>
                <td>
                  <xsl:value-of select="name" />
                </td>
                <td>
                  <xsl:value-of select="dob" />
                </td>
                <td>
                  <xsl:value-of select="rno" />
                </td>
                <td>
                  <xsl:value-of select="course" />
                </td>
              </tr>
            </xsl:for-each>
          </table>
        </center>
      </body>
    </html>
  </xsl:template>
</xsl:transform>

I run my xml file by right clicking the xml file and selecting the option open with mozilla firefox. The same way is working for my friends, but not for me.

I'm getting my output on a straight line without the table like this:

ABC 12/04/2020 REG001 MCA ABC 12/04/2020 REG001 MCA ABC 12/04/2020 REG001 MCA

Can anyone help me with this. Please

Firos
  • 1
  • 4
  • 1
    So how do you run the XSLT code, how do you look at the XSLT result when you say "I'm getting my output on a straight line without the table"? – Martin Honnen Apr 13 '20 at 09:00
  • Basically, it's not your code that's wrong, it's the way you're running it (which you haven't told us about). – Michael Kay Apr 13 '20 at 11:37
  • I just right clicked the xml file and opted open with mozilla firefox. The same way is working on my friends system and they are getting the output, but I'm not getting it. I'm sorry that I forgot to specify how I run it. Thankyou for the reply – Firos Apr 14 '20 at 04:40
  • Perhaps your friends are running an older version of Firefox, before the "same origin" security rule was implemented: https://stackoverflow.com/questions/56999411/firefox-68-local-files-now-treated-as-cross-origin-is-there-a-way-to-override – michael.hor257k Apr 14 '20 at 05:57

1 Answers1

0

I piped the result of xsltproc into lynx (xsltproc Student.xsl Student.xml | lynx -stdin) and got

   CAPTION: Student Details

                                        Name Date of birth Register No Course
                                        ABC  12/04/2020    REG001      MCA
                                        ABC  12/04/2020    REG001      MCA
                                        ABC  12/04/2020    REG001      MCA

so even the text console browser lynx shows a table structure.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Can you suggest me a good tutorial or tell me how to install xsltproc and lynx in my ubuntu 18 system, it will be really helpful for me. Thankyou for the reply. – Firos Apr 14 '20 at 04:44