UL's in XSL

A

adam.mjbarnes

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>
 
R

reclusive monkey

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>
 
A

adMjb

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>
 
J

Johannes Koch

adMjb said:
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>
 
A

adMjb

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?
 
J

Johannes Koch

adMjb said:
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.
 
A

adMjb

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>
 
A

adMjb

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top