UL's in XSL

Discussion in 'XML' started by adam.mjbarnes@gmail.com, Aug 19, 2005.

  1. Guest

    Hi, bet this is simple, but so am I, so can someone help please, my
    HTML is coming out wrong, as you can see from the XSL, I have <ul></ul>
    in-between.

    Any help would be fantastic.
    ---------------
    I have this XML:
    <Bulleted_Text apagenum="1" pagenum="1">
    <Emph cstyle="Bullet">l</Emph>
    text in here
    </Bulleted_Text>
    <Bulleted_Text apagenum="2" pagenum="2">
    <Emph cstyle="Bullet">l</Emph>
    text in here
    </Bulleted_Text>
    ---------------
    this XSL:
    <xsl:template match="bullet">
    <ul>
    <li>
    <xsl:apply-templates/>
    </li>
    </ul>
    </xsl:template>
    ---------------
    My HTML:
    <ul>
    <li>
    text in here
    </li>
    <ul>
    </ul>
    <li>
    text in here
    </li>
    </ul>
    ---------------
    and want this HTML:
    <ul>
    <li>
    text in here
    </li>
    <li>
    text in here
    </li>
    </ul>
     
    , Aug 19, 2005
    #1
    1. Advertising

  2. adMjb Guest

    My XSL has the wrong tag, but that was a typo in this group, so ignore
    that thanks!
     
    adMjb, Aug 19, 2005
    #2
    1. Advertising

  3. You're right ;-)

    Your template basically says "for every "bullet", create a <li> AND
    <ul>", so you should change your XSL to;

    <xsl:template match="bullet">
    <li>
    <xsl:apply-templates/>
    </li>
    </xsl:template>

    then when you call your template in the main body of your XSL, add the
    <ul> tags there, so that they don't repeat with every "bullet".

    <ul>
    <xsl:apply-templates select="bullet"/>
    </ul>
     
    reclusive monkey, Aug 19, 2005
    #3
  4. adMjb Guest

    Hi bit new to XSL So should it look like this?:

    <xsl:template match="bullet">
    <ul>
    <li>
    <xsl:apply-templates/>
    </li>
    <xsl:apply-templates select="bullet"/>
    </ul>
    </xsl:template>
     
    adMjb, Aug 19, 2005
    #4
  5. adMjb wrote:

    > Hi bit new to XSL So should it look like this?:
    >
    > <xsl:template match="bullet">
    > <ul>
    > <li>
    > <xsl:apply-templates/>
    > </li>
    > <xsl:apply-templates select="bullet"/>
    > </ul>
    > </xsl:template>
    >


    No, the <ul></ul> must be in the template for the parent of the
    Bulleted_Text element, e.g.

    <xsl:template match="bulletParent">
    <ul>
    <xsl:apply-templates select="Bulleted_Text"/>
    </ul>
    </xsl:template>

    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
     
    Johannes Koch, Aug 19, 2005
    #5
  6. adMjb Guest

    Hi, the only problem is I have no bulletParent, so can't use that, all
    I have is:

    Example:

    <root>
    <para></para>
    <para></para>
    <bullet></ bullet>
    <bullet></ bullet>
    <bullet></ bullet>
    <para></para>
    <para></para>
    </root>

    So somehow I need to add <UL> befour the first and after the last
    <bullet>
    I.E
    <root>
    <para></para>
    <para></para>
    <ul>
    <bullet></ bullet>
    <bullet></ bullet>
    <bullet></ bullet>
    </ul>
    <para></para>
    <para></para>
    </root>


    Any ideas?
     
    adMjb, Aug 19, 2005
    #6
  7. adMjb wrote:

    > Hi, the only problem is I have no bulletParent, so can't use that, all
    > I have is:


    [...]

    Then in template for root:
    <xsl:apply-templates select="bullet[1]" mode="first"/>

    and

    <xsl:template match="bullet" mode="first">
    <ul>
    <xsl:apply-template match=". | following-sibling::bullet"/>
    </ul>
    </xsl:template>

    <xsl:template match="bullet" mode="first">
    <li>
    <xsl:apply-templates/>
    </li>
    </xsl:template>

    Not tested.
    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
     
    Johannes Koch, Aug 19, 2005
    #7
  8. adMjb Guest

    Hi Johannes,

    Thanks for you help!!, with a bit of working out I got it,

    This worked:

    <xsl:template match="bullet[1]">
    <ul>
    <xsl:apply-templates select=".|following-sibling::bullet"
    mode="first"/>
    </ul>
    </xsl:template>

    <xsl:template match="bullet" mode="first">
    <li>
    <xsl:apply-templates/>
    </li>
    </xsl:template>
    <xsl:template match="bullet">
    <xsl:text disable-output-escaping="yes"/>
    </xsl:template>
     
    adMjb, Aug 19, 2005
    #8
  9. adMjb Guest

    Well it works on a small bit of XML but if you have this:
    it groups all the <bullet> in one place :(
    <root>
    <text>
    text here
    </text>
    <bullet>
    a bullet
    </bullet>
    <bullet>
    b bullet
    </bullet>
    <bullet>
    c bullet
    </bullet>
    <bullet>
    d bullet
    </bullet>
    <bullet>
    e bullet
    </bullet>
    <text>
    text here
    </text>
    <bullet>
    e bullet
    </bullet>
    <bullet>
    f bullet
    </bullet>
    </root>
     
    adMjb, Aug 19, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Replies:
    0
    Views:
    1,033
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Replies:
    1
    Views:
    2,769
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Replies:
    0
    Views:
    481
    Klaus Friese
    Nov 22, 2004
  4. Ray Tayek
    Replies:
    3
    Views:
    527
    Ray Tayek
    Nov 30, 2003
  5. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
Loading...

Share This Page