0
votes

I'm stuck on an xPath expression and how to render it in XSLT. I'd love some help.

SOURCE

A flat stack of "item" elements:

<list>
    <item outline="3" name="grumpy"/>
    <item outline="5" name="monarchists"/>
    <item outline="9" name="dispatch"/>
    <item outline="3" name="parkour"/>
    <item outline="3" name="elves"/>
    <item outline="9" name="hunting"/>
    <item outline="9" name="clueless"/>
    <item outline="3" name="xPath"/>
    <item outline="2" name="newbs"/>
</list>

TEST

Is the value of the preceding element's "outline" attribute greater than the value of the current element's "outline" attribute?

If so, change the value of the current "item" element "outline" attribute to 1.

FAILED XPATH

I can't get past the initial test ...

<xsl:when test="preceding::item[1][@outline &gt; @outline]">

DESIRED OUTPUT

<list>
    <item outline="1" name="grumpy"/>
    <item outline="5" name="monarchists"/>
    <item outline="9" name="dispatch"/>
    <item outline="1" name="parkour"/>
    <item outline="3" name="elves"/>
    <item outline="9" name="hunting"/>
    <item outline="9" name="clueless"/>
    <item outline="1" name="xPath"/>
    <item outline="1" name="newbs"/>
</list>

Please suggest the XSLT too.

Thanks!

1
Why is the first value changed?michael.hor257k
The first value is 1, by default. If I get false from test="preceding::item[1]", I add value 1 to the first element. Aside from that the first item, it follows the rule, no?Jeff Orchard

1 Answers

0
votes

Use

<xsl:template match="item[preceding-sibling::item[1]/@outline > @outline]/@outline">
  <xsl:attribute name="outline">1</xsl:outline>
</xsl:template>

plus the identity transformation template.