Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all values from an element

Tags:

xslt

Given the below XML, how can I get both values with a single statement?
I tried /root/set/name/. with no luck.

 <root>
  <set>
   <name>John</name>
  </set>
  <set>
    <name>Jane</name>
  </set>
 </root>
like image 245
proximityFlying Avatar asked May 19 '26 20:05

proximityFlying


1 Answers

If you want to get the output as John Jane use this XSLT.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="xml" omit-xml-declaration="yes" />
   <xsl:template match="root">
      <xsl:value-of select="normalize-space()" />
   </xsl:template>
</xsl:stylesheet>

this applied on,

<root>
  <set>
   <name>John</name>
  </set>
  <set>
    <name>Jane</name>
  </set>
</root>

will give John Jane

like image 83
Hash Avatar answered May 21 '26 21:05

Hash