Re: [xsl] Finding list items in XHTML

Subject: Re: [xsl] Finding list items in XHTML
From: Chris Loschen <loschen@xxxxxxxxxxxxx>
Date: Thu, 14 Nov 2002 12:02:17 -0500
Hi again!

At 06:25 PM 11/12/02, you wrote:

So the <p> elements did get changed ... you're moving along.

For getting those <li> elements wrapped as proper lists, take a look at

http://www.dpawson.co.uk/xsl/sect2/flatfile.html

Cheers,
Wendell

I seem to keep getting closer, but I'm not quite there yet, and I'm not sure what to do next.
I've now got a first pass which takes my sublist items and surrounds them with
<sublist>...</sublist>. So my input is like this:


***
<p class="hang-text-1"><span class="hang-text-2">&#10148; </span>Which of the following features of the Mighty Vac are important to you? (Check all
that apply.)</p>
<sublist>Extra-long hose</sublist>
<sublist>Extra-long cord</sublist>
<sublist>Extra-high horsepower</sublist>
<sublist>Square head</sublist>
<sublist>Other <i>(Please specify)</i> ______________________</sublist>
<p class="hang-text-12"><span class="hang-text-2">&#10148; </span>How would you rate the service you receive from Acme Industries? (Check one.)
Excellent</p>
<sublist>Good
Fair
Poor</sublist>
<p class="format-10">With closed-end questions, you must often give directions to the respondent (such as
&#8220;Check one&#8221; or &#8220;Please rate from one to five, with five being the best&#8221;).</p>
***


Yes, I know the second sublist didn't really come out right, but my input
isn't always perfect. That will have to be fixed downstream from me.

Now I'm trying to group the <sublist>s into an <ol> and to set up the <li>
for the main lists. In the third pass, I plan to group the <li>s for the main lists.


I read the FAQ page cited above, and tried to implement some of it, but frankly,
I'm not sure it all sunk in very well. I was able to make more sense of Michael
Kay's discussion of grouping adjacent nodes on p. 496 of his book (2nd ed.),
so that's the path I'm trying to follow. However, I'm still off-course somewhere.
Here's part of my stylesheet at present:


***
<xsl:template match="oeb:p[starts-with(.,'&#10148; ')]">
<li><xsl:apply-templates />
<xsl:if test="following-sibling::oeb:sublist[1]">
<xsl:text>&#xA;</xsl:text>
<ol>
<xsl:text>&#xA;</xsl:text>
<xsl:variable name="list-id" select="generate-id(preceding-sibling::p[1])" />
<xsl:for-each select="oeb:sublist[generate-id(preceding-sibling::p[1]) = $list-id]">
<li><xsl:value-of select="." /></li>
<xsl:text>&#xA;</xsl:text>
</xsl:for-each>
</ol>
<xsl:text>&#xA;</xsl:text>
</xsl:if>
</li>
</xsl:template>


<xsl:template match="oeb:sublist" />

<xsl:template match="oeb:span[.='&#10148; ']" />
***

What I'm trying to do is process the list items and the sublists of that list item if there are any.
So my intended output for the above snippet of text would be


***
<li>Which of the following features of the Mighty Vac are important to you? (Check all
that apply.)
<ol>
<li>Extra-long hose</li>
<li>Extra-long cord</li>
<li>Extra-high horsepower</li>
<li>Square head</li>
<li>Other <i>(Please specify)</i> ______________________</li>
</ol>
</li>
<li>How would you rate the service you receive from Acme Industries? (Check one.)
Excellent
<ol>
<li>Good
Fair
Poor</li>
</ol>
</li>
<p class="format-10">With closed-end questions, you must often give directions to the respondent (such as
&#8220;Check one&#8221; or &#8220;Please rate from one to five, with five being the best&#8221;).</p>
***


However, I have several problems. First, the <xsl:if> turns out to be true for EVERY occurrence where there
is a <sublist> anywhere further down in the document, so I get a lot of empty <ol> tags where I don't want them.
Those stop occurring after the last <sublist> in the document. I need to specify that the following-sibling is
immediately adjacent to the current node, but the [1] I inserted to try to do that seems to pick the next occurrence
of <sublist> but not the next node. So my <xsl:if> isn't right.


Next, the stylesheet doesn't insert the <sublist> items into the place where I expect them, so even when I do have
the <ol> tags in the right place, they don't have the content I was trying to set up. My actual output looks like this:


***
<li>Which of the following features of the Mighty Vac are important to you? (Check all
that apply.)
<ol>
</ol>
</li>






<li>How would you rate the service you receive from Acme Industries? (Check one.)
Excellent
<ol>
</ol>
</li>


<p class="format-10">With closed-end questions, you must often give directions to the respondent (such as
&#8220;Check one&#8221; or &#8220;Please rate from one to five, with five being the best&#8221;).</p>
***


I think I understand why the <xsl:if> isn't working, but I don't know how to fix it. I'm not sure why the second
problem is happening at all.


May I ask for a little more help? Thanks so much for all you've helped with so far!


--Chris


----------------------------------------------------------------------------------------
Texterity ~ XML and PDF ePublishing Services
----------------------------------------------------------------------------------------
Chris Loschen, XML Developer
Texterity, Inc.
144 Turnpike Road
Southborough, MA 01772 USA
tel: +1.508.804.3033
fax: +1.508.804.3110
email: loschen@xxxxxxxxxxxxx
http://www.texterity.com/


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



Current Thread