471,356 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

UL's in XSL

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 '05 #1
8 1057
My XSL has the wrong tag, but that was a typo in this group, so ignore
that thanks!

Aug 19 '05 #2
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>

Aug 19 '05 #3
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>

Aug 19 '05 #4
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.)
Aug 19 '05 #5
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?

Aug 19 '05 #6
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.)
Aug 19 '05 #7
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>

Aug 19 '05 #8
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>

Aug 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by CMAR | last post: by
4 posts views Thread by Japhy | last post: by
4 posts views Thread by Winston | last post: by
18 posts views Thread by hendedav | last post: by
6 posts views Thread by stephen.cunliffe | last post: by
5 posts views Thread by shapper | last post: by
omerbutt
5 posts views Thread by omerbutt | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.