simple(?) nested for-each

J

John Estess

The following xml file is converted by the piece of xml below (oil.xsl).
I have the right number of dots for the unordered list items, but it
won't print out the "use's". What am I doing wrong?

XML scrap:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="oil.xsl"?>
<oils>

<oil>
<name>ALCAID-100</name>
<use>Instrument Air Compressor crankcases (except Sullair)</use>
<use>#1 vacuum pump crankcase</use>
</oil>

<oil>
<name>A.T.F.</name>
<use>GT1 &amp; GT2 starting package torque converters</use>
<use>#4 acid pump stroke control boxes</use>
<use>Old R.O. caustic regeneration boxes (diaphragm only)</use>
</oil>
</oils>


XSL stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
<html>
<body>
<h2>Plant Lube Oil Guide</h2>
<table border="0" width="100%">
<tr bgcolor="#F0F0F0">
<th align="left">Oil</th>
<th align="left">Machinery</th>
</tr>
<xsl:for-each select="oils/oil">
<tr>
<td><xsl:value-of select="name"/></td>
<td><ul>
<xsl:for-each select="use">
<li><xsl:value-of select="use"/></li>
</xsl:for-each>
</ul>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet>


John Estess
(e-mail address removed)
 
V

Victor

John Estess wrote:

Instead of this:
<xsl:for-each select="use">
<li><xsl:value-of select="use"/></li>

Try this:
<xsl:for-each select="use">
<li><xsl:value-of select="."/></li>

Your original statement will select the value of oils/oil/use/use.
 
A

Andy Dingley

John Estess said:
What am I doing wrong?

Try this (as a quick guess):

<xsl:for-each select="use">
<li><xsl:value-of select="."/>

You're probably looping through the node set you expect, but
<xsl:for-each> changes the context to each set member element in turn.
Your code had effectively been looking for an extra <uses> element
_within_ each loop element.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top