Difference between <xsl:value-of> and <xsl:for-each>
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Fri Jul 17, 2015 5:04 pm
Difference between <xsl:value-of> and <xsl:for-each>
I'm learning XSLT and I've been looking into the two templates xsl:value-of and xsl:for-each, I've created an XML document that contains data for a restaurant menu; I've also created two XSL documents; one uses the xsl:value-of template; the other uses the xsl:for-each- I then applied each XSL document to the XML document and saved each result as a HTML file, here is my XML document.
This is my XSL document with the xsl:for-each template:
And this is my XSL document with the xsl:value-of template:
I've posted this because I want to learn about what each template does and why; I've noticed that the two XSL documents produce different output results when they're applied to the XML file; could anyone advise me on how I can learn more about the two templates?
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<menu>
<meal>
<mealname>Chicken Madras</mealname>
<description>Chicken pieces in a fiery sauce, with chips</description>
<price>£7.99</price>
</meal>
<meal>
<mealname>Tomato Soup</mealname>
<description>A tomato soup</description>
<price>£3.50</price>
</meal>
</menu>
This is my XSL document with the xsl:for-each template:
Code: Select all
<?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>
<h2>Menu</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Mealname</th>
<th>Description</th>
<th>Price</th>
</tr>
<xsl:for-each select="menu/meal">
<tr>
<td><xsl:value-of select="mealname" /></td>
<td><xsl:value-of select="description" /></td>
<td><xsl:value-of select="price" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?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>
<h2>Menu</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Mealname</th>
<th>Description</th>
<th>Price</th>
</tr>
<tr>
<td><xsl:value-of select="menu/meal/mealname"/></td>
<td><xsl:value-of select="menu/meal/description"/></td>
<td><xsl:value-of select="menu/meal/price"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Difference between <xsl:value-of> and <xsl:for-each>
Hi,
If you edit XSLT in Oxygen, you can hover the mouse pointer over an instruction and see a description of what it does.
For XSLT tutorials for beginners I recommend W3Schools:
XSLT <xsl:value-of> Element
XSLT <xsl:for-each> Element
Regards,
Adrian
If you edit XSLT in Oxygen, you can hover the mouse pointer over an instruction and see a description of what it does.
For XSLT tutorials for beginners I recommend W3Schools:
XSLT <xsl:value-of> Element
XSLT <xsl:for-each> Element
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service