Subject: Re: [xsl] Finding list items in XHTML From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 14 Nov 2002 12:40:11 -0500 |
(c) inside the <ol> (c.1) if it's a sublist, include the first following sibling (c.2) repeat (c.1) until the first following sibling is not a sublist
<xsl:if test="following-sibling::*[1][self::oeb:sublist]"> <!-- we test to see whether we need an <ol> --> <ol> <!-- now we do our first sublist in our special mode --> <xsl:apply-templates mode="listitem" select="following-sibling::*[1][self::oeb:sublist]"/> </ol> </xsl:if>
<xsl:template match="oeb:sublist" mode="listitem"> <!-- make our item and include what's inside this sublist --> <li> <xsl:apply-templates/> </li> <!-- now do the same for the next immediate sibling that's a sublist (if it's not, nothing will happen) --> <xsl:apply-templates mode="listitem" select="following-sibling::*[1][self::oeb:sublist]"/> </xsl:template>
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">➤ </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">➤ </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
“Check one” or “Please rate from one to five, with five being the best”).</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(.,'➤ ')]">
<li><xsl:apply-templates />
<xsl:if test="following-sibling::oeb:sublist[1]">
<xsl:text>
</xsl:text>
<ol>
<xsl:text>
</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>
</xsl:text>
</xsl:for-each>
</ol>
<xsl:text>
</xsl:text>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="oeb:sublist" />
<xsl:template match="oeb:span[.='➤ ']" /> ***
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
“Check one” or “Please rate from one to five, with five being the best”).</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
“Check one” or “Please rate from one to five, with five being the best”).</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!
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Finding list items in XHT, Chris Loschen | Thread | Re: [xsl] Finding list items in XHT, Chris Loschen |
RE: [xsl] Error Using , Schwartz, Rechell R, | Date | Re: [xsl] Error Using , David Carlisle |
Month |