Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   UL's in XSL (http://www.velocityreviews.com/forums/t169744-uls-in-xsl.html)

adam.mjbarnes@gmail.com 08-19-2005 09:36 AM

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>


adMjb 08-19-2005 10:06 AM

Re: UL's in XSL
 
My XSL has the wrong tag, but that was a typo in this group, so ignore
that thanks!


reclusive monkey 08-19-2005 10:14 AM

Re: UL's in XSL
 
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>


adMjb 08-19-2005 10:26 AM

Re: UL's in XSL
 
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>


Johannes Koch 08-19-2005 11:18 AM

Re: UL's in XSL
 
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.)

adMjb 08-19-2005 11:37 AM

Re: UL's in XSL
 
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?


Johannes Koch 08-19-2005 01:30 PM

Re: UL's in XSL
 
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.)

adMjb 08-19-2005 04:12 PM

Re: UL's in XSL
 
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 08-19-2005 05:05 PM

Re: UL's in XSL
 
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>



All times are GMT. The time now is 08:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.