[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Generate a List

Subject: RE: Generate a List
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Tue, 6 Nov 2007 18:05:08 -0600
RE:  Generate a List
I'm guessing that you want something like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"/>

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

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

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

</xsl:stylesheet>


<xsl:value-of select="child::item"/> in your "list" template will only
give you the text values of those child nodes. You were missing the HTML
structure. Also, you can omit the <xsl:value-of/> here; the built-in
template for text nodes is to select the value of the node. Just
<xsl:apply-templates/> inside an HTML element in your template.


~ Scott


-----Original Message-----
From: Alice Ju-Hsuan Wei [mailto:ajwei@xxxxxxxxxxx]
Sent: Tuesday, November 06, 2007 5:57 PM
To: xsl-list
Subject:  Generate a List

Hi,

  I am trying to use the XSLT to generate something simple like a list
and output it to HTML with <ul> and <li> tags.

This is my XSLT:

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

<xsl:template match="list">
<xsl:value-of select="child::item"/>
</xsl:template>

My XML:

<head>Things to do</head>
<list>
<item>Wash the dog</item>
<item>Take out the trash</item>
<item>Check out books on XSLT</item>
<item>Go to the bank</item>
<item>Pay bills</item>
</list>

Output:

<p class="">Things to do</p>

  Wash the dog Take out the trash Check out books on XSLT  Go to the
bank Pay bills
      <br>

Can anyone please tell me what is wrong with my code?

Thanks to those who can help.

Alice

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.