Subject: [xsl] List type, probably a sequence problem (XSL 2) From: "Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 8 Jun 2023 18:40:48 -0000 |
Hi I think this problem should be really simple but whatever I try rapidly gets inordinately complicated. I'm processing documents which contain, among many other things, "list" elements and "steps" elements. Steps really are a special class of list but they are represented by a different element in the schema, for reasons. My stylesheet outputs html, and both lists and steps produce <ol> elements with different attributes. When I meet a list element, I need to decide whether this list should be presented with numbered elements, or lettered elements. The rules are that steps should always be numbered. Lists should always use the alternate scheme to their nearest ancestor, and a list with no ancestor list or step should be numeric. e.g. <document> <list> <li>This list will produce an ol class="decimal"</li> <li/> <li> <list> <li>This list will produce an ol class="alpha"</li> <li> <list> <li>This list will produce an ol class="decimal"</li> <li> <steps> <step>These steps will produce an ol class="decimal"</step> <step> <list> <li>This list will produce an ol class="alpha"</li> <li/> </list> </step> </steps> </li> </list> </li> </list> </li> </list> </document> If steps followed the same rules as lists it would be easy, just construct a sequence of list or steps ancestors: <xsl:variable name="ancestral_lists" as="node*" select="ancestor::list | ancestor::steps" /> and choose class="decimal" if count($ancestral_lists) is even, class="alpha" if odd. But steps are always numbered, so I actually need to count the number of lists after the final step (if any), and invert the numbering/lettering scheme if the sequence included any steps. I thought I could do this with index-of() but unless I'm mistaken that tests the values of the sequence members not their element names. At this point I decided I'm probably on the wrong track and thought I'd ask for help. Is there a nice way to implement this? cheers T
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT transforming from so, LEGAULT, PHILLIP ple | Thread | Re: [xsl] List type, probably a seq, Graydon graydon@xxxx |
Re: [xsl] XSLT transforming from so, LEGAULT, PHILLIP ple | Date | Re: [xsl] List type, probably a seq, Graydon graydon@xxxx |
Month |