xml, xslt file bug

This is an example from WROX Beginning XML book. The xml and xslt files are below. I am not able to display the following using these files. Perhaps there is an error in these code pieces.

Question: Could you please make these code pieces work to produce this image (in a browser)?

Please do not post links etc. All I want is for someone test the code submitted and show me how it is done after debugging it.

xsltLinkappUsersWithXslt.xml
<?xml-stylesheet type="text/xsl" href="appUsers.xslt" ?>
<applicationUsers>
  <user firstName="Joe" lastName="Fawcett" />
  <user firstName="Danny" lastName="Ayers" />
  <user firstName="Catherine" lastName="Middleton" />
</applicationUsers>

Open in new window

appUsers.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <html>
        <head>
          <title>Application Users</title>
        </head>
        <body>
          <table>
            <thead>
              <tr>
                <th>First Name</th>
                <th>Last Name</th>
              </tr>
            </thead>
            <tbody>
              <xsl:apply-templates select="applicationUsers/user" />
            </tbody>
          </table>
        </body>
      </html>
    </xsl:template>

Open in new window

LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
You are making the call to apply-templates on line 16, so you now just need to define the template to use for each user, something like this...
    <xsl:template match="user">
      <tr>
        <td><xsl:value-of select="@firstName" /></td>
        <td><xsl:value-of select="@lastName" /></td>
      </tr>
    </xsl:template>

Open in new window


Add that next to your main template in your stylesheet and you should be right.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Do you mean like:

           <tbody>    -- line 16
              <xsl:apply-templates select="applicationUsers/user" />  -- line 17
              <xsl:template match="user">
                    <tr>
                            <td><xsl:value-of select="@firstName" /></td>
                            <td><xsl:value-of select="@lastName" /></td>
                    </tr>
             </xsl:template>

            </tbody>  -- line 18

Trying it now.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
No put it after line 21 in your XSLT that you posted earlier.

(But before the end element of your stylesheet which you omitted in the XSLT that you posted)
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re:> (But before the end element of your stylesheet which you omitted in the XSLT that you posted)

I have copied from it from the book's sample code download. Here is what I have so far (added after line 21) but I am not quite sure how I need to close it. I will post this error on their site after having spend over 4 hours on it.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <html>
        <head>
          <title>Application Users</title>
        </head>
        <body>
          <table>
            <thead>
              <tr>
                <th>First Name</th>
                <th>Last Name</th>
              </tr>
            </thead>
            <tbody>
              <xsl:apply-templates select="applicationUsers/user" />
            </tbody>
          </table>
        </body>
      </html>
    </xsl:template>

    <xsl:template match="user">
      <tr>
        <td><xsl:value-of select="@firstName" /></td>
        <td><xsl:value-of select="@lastName" /></td>
      </tr>
    </xsl:template>
</closing tag here???>

Open in new window


Thanks for the help.
0
Dave BaldwinFixer of ProblemsCommented:
I downloaded the current version of that code from the PDF sample of the first chapter of version 5 of the book.  Apparently the book was written with Microsoft Word because all of the double quotes were 'smart quotes' which don't work in code.

Here are the two files and they work in Firefox.
appUsers.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <html>
        <head>
          <title>Application Users</title>
        </head>
        <body>
          <table>
            <thead>
              <tr>
                <th>First Name</th>  
                <th>Last Name</th>
              </tr>
            </thead>
            <tbody>
              <xsl:apply-templates select="applicationUsers/user" />
            </tbody>
          </table>
        </body>
      </html>
    </xsl:template>
  <xsl:template match="user">
    <tr>
      <td>
        <xsl:value-of select="@firstName"/>
      </td>
      <td>
        <xsl:value-of select="@lastName"/>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>

Open in new window

appUsersWithXslt.xml
<?xml-stylesheet type="text/xsl" href="appUsers.xslt" ?>
<applicationUsers>
  <user firstName="Joe" lastName="Fawcett" />
  <user firstName="Danny" lastName="Ayers" />
  <user firstName="Catherine" lastName="Middleton" />
</applicationUsers>

Open in new window

0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Nothing special... You've opened the <xsl:stylesheet> tag at the very top, so you must close it...

</xsl:stylesheet>

Open in new window

0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
No luck yet.

Would you please test it to see if it works for you? If so, then paste the working code here.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re:> I downloaded the current version of that code from the PDF sample of the fir...

You could also download sample codes I suppose. Maybe because I have purchased the book it is available to me but not without purchase. I am not sure.
0
Dave BaldwinFixer of ProblemsCommented:
Chapter 1 with the wrong quotes is here: http://media.wiley.com/product_data/excerpt/37/11181621/1118162137-143.pdf   All I changed were their 'smart quotes' to regular quotes.  The code I posted above is correct.
0
Dave BaldwinFixer of ProblemsCommented:
By the way, the version above works in all browsers I have, even IE8.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
It is not working for me. Does it work when you try?
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
And yes I did test it myself too and it works fine.

If it is still not working then it is an issue on your end. You're not using Chrome are you? It won't work.
0
Dave BaldwinFixer of ProblemsCommented:
Yes, it works for me.  As I said, in all browsers, Firefox, Chrome, Opera, and even IE8.  I just checked in IE11 on both IIS7 and Apache 2.4.  Works everywhere.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I tried with explorer, still no luck. There is a note:

"WARNING If you are using Internet Explorer for this or other activities, you’ll probably have to go to ToolsInternet Options and choose the Advanced tab. Under the Security section, check the box in front of Allow Active Content to Run in Files on My Computer. This effectively allows script to work on local files."

But in the latest version of explorer they are hidden somewhere I can't find my way to them. trying. See the image.
Settings.png
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Dave, what version of Chrome have you got it working with? And are you just opening as a local file or are you serving them from a server?
0
Dave BaldwinFixer of ProblemsCommented:
mccarl, I have the current version of Chrome which I believe is 45.  I've opened it both as a file and thru several servers on three different machines.

eghtebas, try Firefox or run it thru a web server.  That message is just about running from a file and not thru a web server.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
Here is a link to the files on one of my hosting accounts:  http://www.yamiam.org/appUsersWithXslt.xml
0
Dave BaldwinFixer of ProblemsCommented:
Internet Options is still there but you have to enter it in the Control Panel search bar to get it to show up.  Or in IE11, you can click on the gear symbol and it is the next to the last item in the dropdown list.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Fire fox worked. I may need to upgrade my Chrome.

Thanks,

Mike
0
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Mike, You're welcome!

Dave, I tried with both Chrome v44.0.2403.157 and updated to the latest, v45.0.2454.85 opening the file directly and both give an error in the console "Unsafe attempt to load URL file:///C:/Temp/ee/appUsers.xslt from frame with URL file:///C:/Temp/ee/appUsersWithXslt.xml. Domains, protocols and ports must match." which when I search on that, it seems it's a common well known issue with Chrome. Just wondering how you might be getting around that (other than serving it from a server) as it is something I need to do reasonably often and I hate having Firefox installed just for that! :)
0
Dave BaldwinFixer of ProblemsCommented:
Actually, I hadn't tried loading it in Chrome from a file.  I just tried it and I get nothing, just a blank screen with no error message.  Chrome is very restrictive about loading anything with a 'file://' protocol.

On the other hand, as a web programmer, none of my work gets loaded as a 'file://' so I rarely test it that way.  While HTML usually works that way, IE doesn't like active content like JavaScript and PHP and ASP simply won't run.  The only time I use 'file://' is when I need to write something that runs locally without a server like help pages.

And because my customers have all the browsers, so do I.  Chrome seems to be the fastest, Firefox is the most useful for development (best and most addons), Opera is the odd one, and IE is often the slowest but is required for testing because so many people use it.  There are more but those are the most mainstream.  Oh, and Safari though I don't have a really recent version.  Can't afford a new Mac.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Ah, ok, no worries. I will continue with Firefox then. Yeah, it's only for quick and dirty XSL tests that I can't be bothered firing up my whole Java app for, and yes I'm too tight to shell out for a proper XML IDE! ;)
0
Dave BaldwinFixer of ProblemsCommented:
For what it's worth, IE and Firefox will load it from a file, Chrome and Opera will not.  Didn't try Safari.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.