check values of 2 XPath-Expressions

Here should go questions about transforming XML with XSLT and FOP.
poroton
Posts: 3

check values of 2 XPath-Expressions

Thu Aug 09, 2018 3:45 pm

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?
Radu
Posts: 5620

Re: check values of 2 XPath-Expressions

Fri Aug 10, 2018 8:06 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
poroton
Posts: 3

Re: check values of 2 XPath-Expressions

Fri Aug 10, 2018 10:58 am

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 :/
Radu
Posts: 5620

Re: check values of 2 XPath-Expressions

Fri Aug 10, 2018 11:22 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
poroton
Posts: 3

Re: check values of 2 XPath-Expressions

Tue Aug 14, 2018 9:27 am

This solves my question. Thank you for helping me. :)

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 1 guest