Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML>HTML with XSL: Bulleted Lists ... argh!

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
NZ
Hi Folks

I'm a bit stumped to say the least. I've got an XML document (a fragment follows) and I've been trying to transform this into HTML using good old XSL. However, the bulleted list that I'm trying to create just doesn't work!

****** DTD Excerpt ******

<!ELEMENT ActReference (para | SubActRef)*>
<!ELEMENT SubActRef (para*)>

****** XML Excerpt ******

<ActReference>
<para>This is some introductory text and a bulleted list follows:</para>
<SubActRef><para>Bullet 1</para></SubActRef>
<SubActRef><para>Bullet 2</para></SubActRef>
<para>And this text continues on from above.</para>
</ActReference>

****** My Question ******

I want to use XSL to transform the above XML fragment into HTML as follows:

<p>This is some introductory text and a bulleted list follows:
(a paragraph end tag could appear here if you think it's necessary e.g. </p>)

<ol type=&quot;a&quot;>
<li>Bullet 1</li>
<li>Bullet 2</li>
</ol>

(a paragraph start tag could appear here if you think it's necessary e.g. <p>)
And this text continues on from above.</p>

*************************

I can't seem to figure out how to do this with XSL. I either end up bulleting the whole <ActReference> paragraph or the section simply disappears! Is it possible to do or do I need to modify the structure of my XML document? Any help or suggestions would be greatly appreciated.

Cheers,
Kenny.
 
My XSL is rather rusty, but I think you're going to struggle to identify the start and end of the list. If you're in a position to change the XML definition, you'll save yourself a lot of headaches by moving to something like this:

<!ELEMENT ActReference (para | SubActList)*>
<!ELEMENT SubActList (SubActRef+)>
<!ELEMENT SubActRef (para*)>

So <SubActList> can be simply replaced with <ul> or <ol> and <SubActRef> with <li>.

I make it a rule of thumb when developing an XML schema always to enclose repeating elements in a &quot;holding&quot; element, for ease of processing later. So instead of
[tt]
<thing>
<wotsit/>
<doodah/>
<widget/>
<widget/>
<widget/>
<widget/>
</thing>
[/tt]
I'd generally go for
[tt]
<thing>
<wotsit/>
<doodah/>
<widgets>
<widget/>
<widget/>
<widget/>
<widget/>
</widgets>
</thing>
[/tt]
Makes it clearer to read too!

-- Chris Hunt
Extra Connections Ltd

The real world's OK for a visit, but you wouldn't want to LIVE there!
 
Yes, I agree that your XML structure needs some work because it looks like you are coding for display which is not what XML is all about. But if the above represents a non-changing pattern, it would be possible to do what you want in XSL:

<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;html&quot;/>
<xsl:template match=&quot;/&quot;>
<html>
<!-- You can insert a head and title in here if you wish -->
<body>
<xsl:for-each select=&quot;ActReference&quot;>
<p><xsl:apply-templates select=&quot;para[1]&quot;/></p>
<ol type=&quot;a&quot;>
<xsl:for-each select=&quot;SubActRef&quot;>
<li><xsl:apply-templates /></li>
</xsl:for-each>
</ol>
<p><xsl:apply-templates select=&quot;para[2]&quot;/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top