SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2003
    Location
    Poland
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy xsl:for-each and text() PROBLEM

    Hi there!
    Firstly, sorry for my English... I'm not a native speaker.
    I've got XML code which looks like this:

    <book>
    <para>
    p1
    <footnote>
    <para>
    f1
    </para>
    </footnote>
    p2
    <footnote>
    <para>
    f2
    </para>
    </footnote>
    p3
    </para>
    </book>

    The effect I would like to achive :

    p1 * p2 * p3

    I've tried to use such XSL stylesheet but it doesn't quite work:

    <xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/book">
    <html>
    <body>
    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="para">
    <xsl:for-each select="text()">
    <xsl:value-of select="."/>

    </xsl:for-each>
    <xsl:apply-templates select="footnote"/>
    </xsl:template>

    <xsl:template match="footnote">
    *
    </xsl:template>

    </xsl:stylesheet>

    The problem is that those * should be 'produced' by template which matches footnote.
    so i don't want them to be some kind of separator.
    other words i would like to proceed the template responsible for footnote after printing out
    p1 and before p2 and then proceed second footnote (write for example *) after p2 and before p3.
    i don't know how to do this because tag para which contains p1, p2 and p3 isn't closed before tag footnote begins.
    i hope it's clear now.
    I would appreciate any help.
    Thanks!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Instead of making your "para" template detect and handle everything that can occur within a "para", just create templates for all those things and let the XSLT engine pick them automatically as the items occur.

    Here's the code:
    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/book">
    <html>
    <body>
    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>
    
    <xsl:template match="para">
    <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="footnote">
    *
    </xsl:template>
    </xsl:stylesheet>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Member
    Join Date
    Jun 2003
    Location
    Poland
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot! I've suspected the solution will be so easy. thank you


Bookmarks

Posting Permissions

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