Re: [xsl] XPath iteration?

Subject: Re: [xsl] XPath iteration?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 12 Jul 2002 15:44:13 +0100
Hi Derek,

> We've got a program that is used to test our XML output by using
> XPath to assert things about the output. I have a situation where I
> want to use an XPath expression to ensure that no two sibling
> elements have the same content. But I don't want to rely on the
> number of these siblings being constant across tests.
>
> So in my example the number of SomeNode's can change over time but
> the test shouldn't have to adapt to that. It should just ensure that
> the SomeNode contents are different.

OK. You can find out if there are any replicas by checking the
preceding siblings of each SomeNode (you don't have to check following
siblings as well because they'll be checked as you go through the
SomeNodes):

  <xsl:if test="SomeNode[. = preceding-sibling::SomeNode]">
    There are two sibling SomeNode elements with the same value.
  </xsl:if>

(BTW I'm assuming that the SomeNode elements are text-only elements so
testing their string values is sufficient to see if their content is
the same.)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread