Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    for each take only the first one

    I have a xml file
    Code:
    <?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
    Code:
    <?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 :
    Code:
    why 1 ?
    because 1
    
    why 2 ?
    because 3
    how can I get all the answer ?

    thank you

    (Edited by mod to clarify separate files)
    Last edited by Alex Vincent; 11-23-2002 at 08:00 PM.

  • #2
    New Coder
    Join Date
    Oct 2002
    Location
    Atlanta
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    xml

    thank you !
    xml is so easy to write an so horrible to read , it a just-one-way language :-))


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •