xml xsl example not working

Hi,

I am trying below example

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

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

<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>

<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>

<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>

<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>

</breakfast_menu>

Open in new window


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

Open in new window


from link
http://www.w3schools.com/xml/xml_xsl.asp

I am getting error when i select xml and xsl and 'run as' xsl transformation
No compatible processor is found for XSLT version null

i supposed to get
Belgian Waffles - $5.95
two of our famous Belgian Waffles with plenty of real maple syrup (650 calories per serving)

Strawberry Belgian Waffles - $7.95
light Belgian waffles covered with strawberries and whipped cream (900 calories per serving)

Berry-Berry Belgian Waffles - $8.95
light Belgian waffles covered with an assortment of fresh berries and whipped cream (900 calories per serving)

French Toast - $4.50
thick slices made from our homemade sourdough bread (600 calories per serving)

Homestyle Breakfast - $6.95
two eggs, bacon or sausage, toast, and our ever-popular hash browns (950 calories per serving)

Please advise
LVL 7
gudii9Asked:
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.

hieloCommented:
As far as I know, every xsl stylesheet requires <xsl:stylesheet> (or <xsl:transform> -- http://www.w3.org/TR/xslt#stylesheet-element) element, which contains all your transformations.

Try saving the following as "breakfast.xsl" in the same folder where you have "breakfast.xml":
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html"/>
	
	<xsl:template match="/"> 
        <html>
        <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
        <xsl:for-each select="breakfast_menu/food">
          <div style="background-color:teal;color:white;padding:4px">
            <span style="font-weight:bold"><xsl:value-of select="name"/> - </span>
            <xsl:value-of select="price"/>
            </div>
          <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
            <p>
            <xsl:value-of select="description"/>
            <span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving)</span>
            </p>
          </div>
        </xsl:for-each>
        </body>
        </html>
	</xsl:template>
</xsl:stylesheet>

Open in new window


To test the above xsl file directly on the browser, in breakfast.xml "link" to the xsl file above:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="breakfast.xsl"?>
<breakfast_menu>...</breakfast_menu>

Lastly, open Firefox, and open breakfast.xml

FYR:
https://msdn.microsoft.com/en-us/library/ms256204%28v=vs.110%29.aspx
http://www.ibm.com/developerworks/library/x-tiphtml/
http://www.ibm.com/developerworks/library/x-tipxslt/index.html
0
gudii9Author Commented:
both in same folder of eclipse as attached. Do i need to refer xsl name in xml somewhere or otherway?

i wan to run in the eclipse though not in browser
xmlXsl.png
0
hieloCommented:
Use the xsl file I posted above.  Your screenshot shows the one that doesn't have the <xsl:stylesheet> element.  As for the transformation, refer to:
https://docs.oracle.com/javase/tutorial/jaxp/xslt/transformingXML.html

Look on the heading "Writing the Basic Program"
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

gudii9Author Commented:
My code on other laptop has below
 <xsl:template match=
 But it does not have below
 <h2> <xsl:apply-templates
what is the difference between these two. when to use which one and why we need templates in XSL.
I am also reading that link which is good.
please advise
0
hieloCommented:
You are not obligated to create templates for your nodes -- ex: <xsl:template match="food">...</xsl:template>.  You can do all the processing in the "starting/entry" template ( in the example you posted, this is <xsl:template match="/">...</xsl:template> -- if you are familiar with c/c++, think of it a main).  However, the advantage of templates is that they simplify the processing logic significantly.

If you are completely new to xsl, I suggest you invest some time reading at least the first three chapters of Tidwell's book:
https://www.google.com/search?tbm=bks&hl=en&q=xsl%2B%22The+Obligatory+Hello+World+Example%22+site%3Abooks.google.com

If you feel like skipping Chapter 1, I suggest you at least read the "XML Basics" section. The section titled "How a Stylesheet is Processed" in Chapter 2 is particularly illuminating. Chapter three covers node types and the "context node".  These chapters should demystify these concepts and give you a good foundation into xsl.

Regards,
Hielo
0
gudii9Author Commented:
i di d added
<?xml-stylesheet type="text/xsl" href="breakfast.xsl"?>
to xml file i see in compatible xsl error as attached. please advise.
i will try to buy that book as well soon.
compatibleErr.png
0
hieloCommented:
>> <?xml-stylesheet type="text/xsl" href="breakfast.xsl"?>
That was meant for you to do testing by opening the XML file directly through the browser.  I don't know if Eclipse has built-in capabilities to do XSL transformation, but to the oracle link I referred you to earlier shows you how to do so in java.
0
gudii9Author Commented:
http://www.vogella.com/tutorials/XSLT/article.html

i tried this example which works fine though
0
gudii9Author Commented:
<?xml version="1.0"?>
  <!-- This is a comment -->
<people>
  <address type="personal">
    <name>Lars </name>
    <street> Test </street>
    <telephon number="0123" />
  </address>
  <address type="personal">
    <name>Joe </name>
    <street> Test2 </street>
    <telephon number="1234" />
  </address>
  <address type="business">
    <name>Jim</name>
    <street> Test3 </street>
    <telephon number="2345" />
  </address>
</people> 

Open in new window


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

  <xsl:output method="xml" />

  <!-- Copy everything -->
  <xsl:template match="node()">
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

  <!-- Do some adjustments for the address -->
  <xsl:template match="address">
    <xsl:element name="place-where-person-live">
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

  <!-- Put the name in a <hubba> tag -->
  <xsl:template match="name">
    <xsl:element name="name">
      <hubba>
        <xsl:apply-templates />
      </hubba>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet> 

Open in new window


ABOVE code from link is similar to my code below

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

Open in new window

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="breakfast.xsl"?>
<breakfast_menu>

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

<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>

<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>

<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>

<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>

</breakfast_menu>

Open in new window

still do not work. I may missing some thing.
please advise
0
hieloCommented:
Like I said, '<?xml-stylesheet type="text/xsl" href="breakfast.xsl"?>' was meant for you to test on the browser.  Since you are not using the browser, get rid of it.
0
gudii9Author Commented:
i removed still same kind of err.
err3.png
0
hieloCommented:
Like I said, you have to have your xsl code within:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0"> ... </xsl:stylesheet>

Copy and paste the code from my first post and try it.
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
gudii9Author Commented:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="breakfast_menu/food">
  <div style="background-color:teal;color:white;padding:4px">
    <span style="font-weight:bold"><xsl:value-of select="name"/> - </span>
    <xsl:value-of select="price"/>
    </div>
  <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
    <p>
    <xsl:value-of select="description"/>
    <span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving)</span>
    </p>
  </div>
</xsl:for-each>
</body>
</xsl:stylesheet>

Open in new window


<?xml version="1.0"?>

<breakfast_menu>

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

<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>

<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>

<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>

<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>

</breakfast_menu>

Open in new window


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


Belgian Waffles
$5.95
Two of our famous Belgian Waffles with plenty of real maple syrup
650



Strawberry Belgian Waffles
$7.95
Light Belgian waffles covered with strawberries and whipped cream
900



Berry-Berry Belgian Waffles
$8.95
Light Belgian waffles covered with an assortment of fresh berries and whipped cream
900



French Toast
$4.50
Thick slices made from our homemade sourdough bread
600



Homestyle Breakfast
$6.95
Two eggs, bacon or sausage, toast, and our ever-popular hash browns
950

Open in new window

it seemed worked as above finally
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.