0

Suppose there is such a document:

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <paths>
    <item>
      <name>username</name>
      <path>user/name</path>
    </item>
    <item>
      <name>useremail</name>
      <path>concat(user/name,': ',user/email)</path>
    </item>
  </paths>
  <user>
    <name>John</name>
    <email>john@gmail.com</email>
  </user>
</root>

the output required to obtain such a document:

<?xml version="1.0" encoding="utf-8"?>
<results>
  <item name="username" value="John"/>
  <item name="useremail" value="John: john@gmail.com"/>
</results>

The point is that the number of path elements can vary, and their values can refer to different elements of the source document (including using functions).

Is there a way to use the values of some elements as an expression of the search for other?

Vladimir Shiyanov
  • 1,236
  • 16
  • 18
  • Not easy (esp. if the paths are only partial, as shown in your example). See something similar here: http://stackoverflow.com/a/26982656/3016153 – michael.hor257k Apr 25 '17 at 11:24
  • The paths would be to make absolute, if it easier to solve the problem – Vladimir Shiyanov Apr 25 '17 at 11:56
  • it would be much easier to eliminate the problem and find an approach that does not require evaluating strings as XPath expressions. And I am not even sure what you mean by "*including using functions*". Which XSLT processor will you be using? – michael.hor257k Apr 25 '17 at 12:10
  • What you want is to execute XPath dynamically. It doesn't look like it can be done easily. http://stackoverflow.com/questions/4630023/dynamic-xpath-in-xslt. – John Ernst Apr 26 '17 at 02:03
  • Thanks for the comments. I understand that this is difficult, and decided to move methods the content of the attributes values in another layer. – Vladimir Shiyanov Apr 26 '17 at 08:56

0 Answers0