This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: List Item Query
- From: Peter Davis <pdavis152 at attbi dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sun, 3 Mar 2002 20:31:23 -0800
- Subject: Re: [xsl] List Item Query
- References: <F372fPmsSVhGOD6gx3l00005e28@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Sunday 03 March 2002 19:12, Sheryl Cia wrote:
> How can i read the values • or (1) of the item tag so that i
> can test which list tag should be applied?
> If i read the value • i can render it in html as:
> <ul>
> <li>Text1 here....</li>
> <li>Text2 here....</li>
> <li>Text3 here....</li>
> </ul>
> The value • from the <item> tag shall be removed.
>
> The same with the numbered list.
This part is relatively easy to answer, since you can use a bunch of
substring() calls to devise an expression to test for this. Something like
this (untested):
<xsl:template match="list">
<xsl:choose>
<xsl:when test="child::item[substring(normalize-space(.), 1, 2) = '('
and string(number(substring(substring-before(normalize-space(.), ')'), 1)))
!= 'NaN'][1]">
<ol class="">
<xsl:for-each select="child::item">
<li>
<!-- I'll leave it up to you to figure out how to remove the (1)
from the output. -->
<xsl:apply-templates/>
</li>
</xsl:for-each>
</ol>
</xsl:when>
<xsl:otherwise>
[see below]
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The second part depends on what the • entity expands to. You cannot see
the string "•" in the value of the element. So you have to test to see
if the element starts with the value of the • entity (you could pass
this in as parameter to the stylesheet since the stylesheet probably couldn't
read the same DTD as the input document). If it is "*", then you can test
for child::item[starts-with(normalize-space(.), '*')][1]. Make another
<xsl:when> element in the <xsl:choose> above and put that as the test.
Now for the preaching: you really should consider redesigning your XML input.
I know you probably don't have control over the format, but if you do, you
should definitely change it. Having separate elements for the different
types of lists (like HTML does - <ol> and <ul>) would make this problem tons
easier to solve (obviously). Bitch at whoever controls your input to
consider changing it. Also, since it is generally bad practice to use the
content of an element to determine the result, you should definitely have an
<xsl:otherwise> in the <xsl:choose> that handles the case that neither (nn)
or • were found at the start of the <item>.
--
Peter Davis
Honesty is the best policy, but insanity is a better defense.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list