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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Bulleted list using XSL

Status
Not open for further replies.
Aug 17, 2000
23
US
Hello,

Having difficulty rendering bulleted list using XSL. Here is
a sample of the code.

<INVENTORY>
<ID>000001</ID>
<ITEM>CAMERA</ITEM>
<DESCRIPTION>
<P>WAVEFRONT SENSOR</P>
<P>SEGMENT PHASING</P>
<P>ROTATOR</P>
<P>PARTICLE DETECTOR</P>
</DESCRIPTION>

Not sure how to implement --

<xsl:for-each select=&quot;//INVENTORY/???&quot;

Any ideas?? Thanks for the help in advance.

GodofSmallThings
 
How do you want the output to look? Which elements should be bulleted?
 
Mulligh,

For every item in Inventory. I want the items under
DESCRIPTION to render as a square bullete. (The above
sample code shows only one item in inventory).

- GodofSmallThings.
 
Ah, then you have a problem because your XML file is too flat. All of the <ITEM> and <DESCRIPTION> elements are siblings of each other (they are all at the same level hierarchically). You need to add more levels to your XML source so that the style sheet can tell one item from another.

The simplest way to take care of this is to wrap each item in another element. For instance, note each item is wrapped in an <ITEMS> element:

<INVENTORY>
<ITEMS>
<ID>000001</ID>
<ITEM>CAMERA</ITEM>
<DESCRIPTION>
<P>WAVEFRONT SENSOR</P>
<P>SEGMENT PHASING</P>
<P>ROTATOR</P>
<P>PARTICLE DETECTOR</P>
</DESCRIPTION>
</ITEMS>
...
</INVENTORY>

Once you do this, this style sheet will do what you want:

<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;html&quot;/>
<xsl:template match=&quot;/&quot;>
<html>
<head>
<title></title>
</head>
<body>
<xsl:for-each select=&quot;//ITEMS&quot;>
<p><xsl:apply-templates select=&quot;ITEM&quot;/></p>
<ul type=&quot;square&quot;>
<xsl:for-each select=&quot;DESCRIPTION/P&quot;>
<li><xsl:apply-templates/></li>
</xsl:for-each>
</ul>
</xsl:for-each>
</body>
</html>

</xsl:template>
</xsl:stylesheet>
 
Beautiful...

Thanks for clearly explaining the process and taking time
to write out the code! Excellent work!!

GodofSmallThings





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top