0

I have the my XML file as below:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="menu.xsl" type="text/xsl" xmlns:k="Kitchen" ?>
<k:breakfast_menu>

<k:food>
<k:name>Belgian Waffles</k:name>
<k:price>$5.95</k:price>
<k:description>Two of our famous Belgian Waffles with plenty of real maple syrup</k:description>
<k:calories>650</k:calories>
</k:food>

</k:breakfast_menu>

The XSLT file is:

<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:k="Kitchen">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="k:breakfast_menu/k:food">
  <div style="background-color:teal;color:white;padding:4px">
    <span style="font-weight:bold"><xsl:value-of select="k:name"/> - </span>
    <xsl:value-of select="k:price"/>
    </div>
  <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
    <p>
    <xsl:value-of select="k:description"/>
    <span style="font-style:italic"> (<xsl:value-of select="k:calories"/> calories per serving)</span>
    </p>
  </div>
</xsl:for-each>
</body>
</html>

But this doesn't load it.

I am working off an example and the original example works but it didn't use namespaces. I have added the xmlns:k="Kitchen" namespace and corresponding changes to both files but now the browser doesn't display the data.

What I really want to see is how the XSLT works when the the source XML file uses namespaces and hence my changes. Anyone can see what am I doing wrong?

1 Answer 1

1

You've added xmlns:k="Kitchen" within a processing instruction, where it has no effect. It needs to go on an element.

Nice to see someone using "simplified stylesheets" - an underused feature, in my view.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.