0

I am very new to XSLT and want your help

I have an XML with below format :

    <?xml version="1.0" encoding="UTF-8"?>
<Rowset>
       <Row>
               <ActualHour>0.64</ActualHour>
       </Row>
       <Row>
               <ActualHour>0.64</ActualHour>
       </Row>
       <Row>
               <ActualHour>0.64</ActualHour>
       </Row>      
</Rowset>

I want to know how can I check whether "ActualHour" has same values across different "Row" node using XSLT?

Thanks in advance.

1 Answer 1

1

Try:

<xsl:template match="/Rowset">
    <output>
       <xsl:value-of select="not(Row/ActualHour!=Row/ActualHour)"/>
    </output>    
</xsl:template>

The result in your example will be:

<?xml version="1.0" encoding="UTF-8"?>
<output>true</output>

With an input like:

<Rowset>
       <Row>
               <ActualHour>0.64</ActualHour>
       </Row>
       <Row>
               <ActualHour>0.65</ActualHour>
       </Row>
       <Row>
               <ActualHour>0.64</ActualHour>
       </Row>      
</Rowset>

the result will be false.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. It works like a charm. If you don't mind, the .. is it used as a foreach here?
Not sure what you mean by that.
In your anser, you mentioned this line : "[ActualHour!=../Row/ActualHour]". How exactly does it work? Like a for loop?
It works like a set comparison, because that's what it is. According to the XPath specification, "the comparison will be true if and only if there is a node in the first node-set and a node in the second node-set such that the result of performing the comparison on the string-values of the two nodes is true."
Thank you Michael :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.