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 5 of 5

Thread: Xml / Xsl

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Xml / Xsl

    with this xml file

    <conditions>
    <titlePara>title 1</titlePara>
    <para>para 10</para>
    <titlePara>title 2</titlePara>
    <para>para 20</para>
    <para>para 21</para>
    </conditions>

    and this xsl file

    <xsl:template match="/">
    <xsl:for-each select="/conditions/titlePara">
    <div class='title1'>
    <xsl:value-of select="."/>
    </div>
    <xsl:for-each select="/conditions/para">
    <div class='ParaNormal'>
    <xsl:value-of select="."/>
    </div>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    I get

    title 1
    para 10
    para 20
    para 21
    title 2
    para 10
    para 20
    para 21

    how can I get

    title 1
    para 10
    title 2
    para 20
    para 21

    THANK YOU !

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Forgive my rusty XSLT, but in your first for-each loop, I believe you could do something like:

    <xsl:if test="count(following-sibling::titlePara) &gt; 0">
    <xsl:variable name="offset" select="position() + following-sibling::titlePara/position()"/>
    </xsl:if>

    Then maybe something like:

    <xsl:for-each select="para">
    <xsl:if test="position() &lt; $offset">
    <xsl:value-of select="."/>
    </xsl:if>
    </xsl:for-each>

    Inside the very first for-each.

    This is all of the top of my head, and probably I made some errors, but it might be a start.

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

    no

    no I get an error !

    it is so difficult to read this xml !

    thanks anyway for helping

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this stylesheet:

    <?xml version="1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="html"/>
    <xsl:template match="/">
    <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="/conditions/titlePara">
    <div class='title1'>
    <xsl:value-of select="."/>
    </div>
    </xsl:template>

    <xsl:template match="/conditions/para">
    <div class='ParaNormal'>
    <xsl:value-of select="."/>
    </div>
    </xsl:template>

    </xsl:stylesheet>


    patrick

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

    yes !!!

    now I have a good idea , how it works

    simple when you know it :-)


    zhank you


  •  

    Posting Permissions

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