By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

XSL:for-each

P: n/a
Hello!

When looking at a file, test1.xml in IExplorer6 or Firefox I see:

1. cup

I want the result to be:
1. cup
2. spoon
3. chair

Why arenīt all parts listed?

Here is the code (test1.xml + test1.xsl):

test1.xml :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="test1.xsl"?>
<!DOCTYPE test
[<!ELEMENT test (head)>
<!ELEMENT head (part*)>
<!ELEMENT part (#PCDATA)>]>
<test>
<head>
<part>cup </part>
<part>spoon </part>
<part>chair</part>
</head>
</test>
-----------stop------------------------------------------

test1.xsl :

<?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>

<ol>
<xsl:for-each select="test/head">
<li><xsl:value-of select="part"/></li>
</xsl:for-each>
</ol>

</body>
</html>
</xsl:template>

</xsl:stylesheet>

----------stop-------------

Mar 19 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

Geranium wrote:
<xsl:for-each select="test/head"> <xsl:for-each select="test/head/part"> <li><xsl:value-of select="part"/></li>

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

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 19 '06 #2

P: n/a
Thank you so much!
That DOT!
Mar 19 '06 #3

P: n/a
Geranium wrote:
Hello!

When looking at a file, test1.xml in IExplorer6 or Firefox I see:

1. cup

I want the result to be:
1. cup
2. spoon
3. chair

Why arenīt all parts listed?


You should consider using a template, not for-each.

For-each is best kept for processing out-of-sequence data,
or for reordering the data. If all you want is the data in
document order, use templates.

<xsl:template match="/">
<html>
<head><title>Test</title></head>
<body>
<ol>
<xsl:apply-templates select="test/head/part"/>
</ol>
</body>
</html>
</xsl:template>

<xsl:template match="part">
<li>
<xsl:value-of select="part"/>
</li>
</xsl:template>

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Mar 19 '06 #4

P: n/a
On Sun, 19 Mar 2006 23:46:38 +0000, Peter Flynn
<pe********@m.silmaril.ie> wrote:
<xsl:template match="part">
<li>
<xsl:value-of select="part"/>


<xsl:value-of select="."/>
--
Eric Amick
Columbia, MD
Mar 20 '06 #5

P: n/a
Eric Amick wrote:
On Sun, 19 Mar 2006 23:46:38 +0000, Peter Flynn
<pe********@m.silmaril.ie> wrote:
<xsl:template match="part">
<li>
<xsl:value-of select="part"/>


<xsl:value-of select="."/>


Duuh. Yes, sorry. Too much St Patrick's Day :-)

///Peter
Mar 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.