0

I have the following XML structure:

<list>
   <value>
      <firstname>mark1</firstname>
      <address>my address</address>
      <city>bruxelles</city>
      <id>1</id>
      <lastname>durand</lastname>
   </value>
   <value>
      <firstname>mark2</firstname>
      <address>my address</address>
      <city>bruxelles</city>
      <id>2</id>
      <lastname>durand</lastname>
   </value>
   <value>
      <firstname>mark3</firstname>
      <address>my address</address>
      <city>bruxelles</city>
      <id>3</id>
      <lastname>durand</lastname>
   </value>
</list>

When I do /list/value/firstname/text(), I have:

mark1
mark2
mark3

As I would like to have something like

1 - mark1
2 - mark2
3 - mark3

I tried: concat(/list/value/id/text(),"-", /list/value/firstname/text())

But it would only return the first set, i.e.

1-mark1

Is there a way to achieve what I'm looking for and loop over the nodes?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Christian68
  • 845
  • 4
  • 13
  • 24
  • 1
    Why have you asked 45 questions over 6 years and accepted 0 answers? I suggest you go back and accept some of the answers that have helped you, or read [ask] to learn how to use this site better if you're not finding *anything* to be acceptable. – kjhughes Mar 15 '21 at 18:16
  • Hi kjhughes - thanks for your message. I'm very grateful to the Stack community and on many occasions in my message I say "Thank you". I was unaware that I had to formally accept the answers. But yes, I find all answers to be acceptable and again, thanks to the community. Best regards - C – Christian68 Mar 15 '21 at 18:42
  • You're welcome. Please do [**accept**](https://meta.stackexchange.com/q/5234/234215) those answers to this question and to past questions that have helped you. (It's faster, easier, and more following with site protocol than dropping a "thank you" comment.) You can also upvote questions asked by you or others. These quality signals help surface the most helpful answers and make the site more valuable to future readers/searchers. Thanks. – kjhughes Mar 15 '21 at 19:11

1 Answers1

1

XPath 1.0

Not possible without assistance of hosting language.

XPath 2.0

This XPath,

/list/value/concat(firstname, ' - ', id)

will return

1 - mark1
2 - mark2
3 - mark3

as requested.

kjhughes
  • 106,133
  • 27
  • 181
  • 240