PDA

View Full Version : for each take only the first one


jeorg
11-22-2002, 04:40 PM
I have a xml file

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml:stylesheet type="text/xsl" href="faqs.xsl" ?>
<faqs>
<faq>
<question>why 1 ?</question>
<answer>because 1</answer>
<answer>because 2</answer>
</faq>
<faq>
<question>why 1 ?</question>
<answer>because 3</answer>
<answer>because 4</answer>
</faq>
</faqs>

a xsl file

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:for-each select="faqs/faq">
<h2 class='title'>
<xsl:value-of select="question"/>
</h2>
<p class='Para'>
<xsl:value-of select="answer"/>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


but I get only
the first answer

in that case :

why 1 ?
because 1

why 2 ?
because 3


how can I get all the answer ?

thank you

(Edited by mod to clarify separate files)

dhtroy
11-25-2002, 04:30 PM
It's because the parser finds a matching item for your value-of clause, right when it hits that first <answer> tag. The simple solution is to wrap your <answer> tags within a "parent-level" tag such as ...

<answers>
<answer>my first answer</answer>
<answer>my second answer</answer>
</answers>

and have another for-each loop

Hope that helps.

jeorg
11-25-2002, 07:08 PM
thank you !
xml is so easy to write an so horrible to read , it a just-one-way language :-))