|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: List type, probably a sequence problem (XSL 2)
can't you track this on the way down rather than looking up?
<xsl:stylesheet version="3.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:template match="document">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="list">
<xsl:param name="num" select="true()" tunnel="yes"/>
<ol style="list-style-type: {if($num)then 'decimal' else 'lower-roman'}">
<xsl:apply-templates>
<xsl:with-param name="num" select="not($num)" tunnel="yes"/>
</xsl:apply-templates>
</ol>
</xsl:template>
<xsl:template match="steps">
<xsl:param name="num" select="true()" tunnel="yes"/>
<ol style="lxist-style-type: decimal">
<xsl:apply-templates>
<xsl:with-param name="num" select="false()" tunnel="yes"/>
</xsl:apply-templates>
</ol>
</xsl:template>
<xsl:template match="li|step">
<li>
<xsl:apply-templates/>
</li>
</xsl:template>
</xsl:stylesheet>
On Thu, 8 Jun 2023 at 19:40, Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> 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
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by
> email <>)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








