RE: [xsl] List Item Query

Subject: RE: [xsl] List Item Query
From: Joshua.Kuswadi@xxxxxxxxxxxxxxxxxxxx
Date: Mon, 4 Mar 2002 17:03:18 +1100
Sheryl wrote:
> <list>
> <item>&bull; Text1 here....</item>
> <item>&bull; Text2 here....</item>
> <item>&bull; Text3 here....</item>
> </list>
> 
> <list>
> <item>(1) Text1 here....</item>
> <item>(2) Text2 here....</item>
> <item>(3) Text3 here....</item>
> </list>
> 
> How can i read the values &bull; or (1) of the item tag so that i
> can test which list tag should be applied?
> If i read the value &bull; i can render it in html as:
> <ul>
> <li>Text1 here....</li>
> <li>Text2 here....</li>
> <li>Text3 here....</li>
> </ul>
> The value &bull; from the <item> tag shall be removed.
> 
> The same with the numbered list.
> <ol class="">
> <li>Text1 here....</li>
> <li>Text2 here....</li>
> <li>Text3 here....</li>
> </ol>

Hi Sheryl,

If you have the assumption that the list type can be determined from the first list/item element, and secondly that if the item starts with '(' then it is an ordered list, otherwise it is an ordered list, you can try the following:

<xsl:template match="list">
 <xsl:choose>
  <xsl:when test="starts-with(item[1], '(')">
   <ol class="">
    <xsl:apply-templates select="item" mode="ol"/>
   </ol>
  </xsl:when>
  <xsl:otherwise>
   <ul>
    <xsl:apply-templates select="item" mode="ul"/>
   </ul>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template match="item" mode="ol">
 <li><xsl:value-of select="substring(., 5)"/></li>
</xsl:template>
<xsl:template match="item" mode="ul">
 <li><xsl:value-of select="substring(., 6)"/></li>
</xsl:template>

Hope that helps,
Joshua

------------------------------------------------------------------------------
This message and any attachment is confidential and may be privileged or otherwise protected from disclosure.  If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone.





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread