Page 1 of 1

check values of 2 XPath-Expressions

Posted: Thu Aug 09, 2018 3:45 pm
by poroton
Hi,

I want to test if values of nodes are the same:

Code: Select all


<xsl:if test="'//ab:person1/ab:gender' and '//ab:person2/ab:gender' '">
Why isn't this working?

Re: check values of 2 XPath-Expressions

Posted: Fri Aug 10, 2018 8:06 am
by Radu
Hi,

You usually need to use the "=" sign to compare two nodes or strings in XSLT. But there is not much context in what you posted to help further.
Usually when you post about an XSLT problem, posting a small sample XML and XSLT stylesheet help others understand better what you want to do.

Regards,
Radu

Re: check values of 2 XPath-Expressions

Posted: Fri Aug 10, 2018 10:58 am
by poroton
I changed my example to following (working) problem case:


Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ab="http://ab.example.net/V1.0/Schema" exclude-result-prefixes="ab">
<xsl:template match="/">
<Data>
<xsl:if test="'//ab:kov-data/ab:person1/ab:gender' = '//ab:kov-data/ab:person2/ab:gender'">
:)
</xsl:if>
</Data>
</xsl:template>
</xsl:stylesheet>

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<ab:kov-data xmlns:ab="http://ab.example.net/V1.0/Schema">
<ab:person1>
<ab:gender>m</ab:gender>
</ab:person1>
<ab:person2>
<ab:gender>m</ab:gender>
</ab:person2>
</ab:kov-data>
The result should be:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?><Data>:)</Data>
Using "=" didn't worked :/

Re: check values of 2 XPath-Expressions

Posted: Fri Aug 10, 2018 11:22 am
by Radu
Hi,

If you add those extra ' simple quotes around XPath expressions, they become simple strings.
So you should remove the simple quotes and obtain something like:

Code: Select all

<xsl:if test="//ab:kov-data/ab:person1/ab:gender = //ab:kov-data/ab:person2/ab:gender">
Regards,
Radu

Re: check values of 2 XPath-Expressions

Posted: Tue Aug 14, 2018 9:27 am
by poroton
This solves my question. Thank you for helping me. :)