freelanceprogrammers.org Forum Index » XML / XSL

XML Nested List to HTML (via XSL)


View user's profile Post To page top
loftymj Posted: Fri Mar 11, 2005 1:54 am


Joined: 09 Feb 2005

Posts: 4
XML Nested List to HTML (via XSL)
A question regarding transforming a *nested* list from XML to HTML via XSL:

I have the following list structure in my source (structured FrameMaker):
1. Do this stuff.
a. first thing to do
b. second thing to do
c. last thing to do
2. Now do this.
3. Finally do this.
__________

Saved as XML, it looks like this (as it should):
<List listType = "ordered">
<ListItem>Do this stuff.</ListItem>
<List listType = "ordered">
<ListItem>first thing to do</ListItem>
<ListItem>second thing to do</ListItem>
<ListItem>last thing to do</ListItem>
</List>
<ListItem>Now do this.</ListItem>
<ListItem>Finally do this.</ListItem>
</List>
___________

My EDD/DTD allows a List within a ListItem.
___________

My XSL for list elements looks like this:
<xsl:template match="List">
<xsl:choose>
<xsl:when test="@listType[.=`unordered`]">
<ul>
<xsl:for-each select="ListItem">
<li>
<xsl:apply-templates />
</li>
</xsl:for-each>
</ul>
</xsl:when>
<xsl:when test="@listType[.=`ordered`]">
</xsl:for-each>
<ol>
<xsl:for-each select="ListItem">
<li>
<xsl:apply-templates />
</li>
</xsl:for-each>
</ol>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

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

<xsl:template match="List/para">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
______________

My HTML output looks like this (missing the nested list):
<ol>
<li>Do this stuff.</li>
<li>Now do this.</li>
<li>Finally do this.</li>
</ol>
_______________

What am I missing in order to get the nested list?

The transform works great for both ordered and unordered lists as long as there
is no nested list.

I`m using the freebie application XSL Tester to write and test my XSL if that
matters. If there is something better (but still free), let me know.

I know it must be something simple. Help!

I`m on digest so please send replies to me directly at
mailto:marsha.lofthouse@....

Thanks in advance,

M

Marsha Lofthouse
Information Development
Motorola, Inc., Public Safety Applications
Boulder Design Center
Marsha.Lofthouse@...
303.527.4178
Reply with quote
Send private message
View user's profile Post To page top
okeefenc Posted: Fri Mar 11, 2005 2:06 am


Joined: 11 Mar 2005

Posts: 7
XML Nested List to HTML (via XSL)
At 12:54 PM 3/10/2005 -0700, you wrote:
>My XSL for list elements looks like this:
><xsl:template match="List">
> <xsl:choose>
> <xsl:when test="@listType[.=`unordered`]">
> <ul>
> <xsl:for-each select="ListItem">
> <li>
> <xsl:apply-templates />
> </li>
> </xsl:for-each>
> </ul>
> </xsl:when>
> <xsl:when test="@listType[.=`ordered`]">
> </xsl:for-each>
> <ol>
> <xsl:for-each select="ListItem">
> <li>
> <xsl:apply-templates />
> </li>
> </xsl:for-each>
> </ol>
> </xsl:when>
> <xsl:otherwise>
> <xsl:apply-templates />
> </xsl:otherwise>
> </xsl:choose>
></xsl:template>
>
><xsl:template match="ListItem">
> <xsl:apply-templates />
></xsl:template>
>
><xsl:template match="List/para">
> <p>
> <xsl:apply-templates />
> </p>
></xsl:template>

Your XSL should be something like this:

<xsl:template match="List[@listType=`unordered`]">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match="List[@listType=`ordered`]">
<ol>
<xsl:apply-templates/>
</ol>
</xsl:template>

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

You`re trying to write procedural code, and XSL is declarative. I highly
recommend that you read Michael Kay`s XSLT Programmer`s Reference.

Regards,

Sarah O`Keefe



^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sarah O`Keefe okeefe@...
Scriptorium Publishing Services, Inc.
Accelerating Knowledge http://www.scriptorium.com
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help