Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This XSLT:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes" method="text"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/*"&gt; &lt;xsl:apply-templates select="*/*[1]/*"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*"&gt; &lt;xsl:variable name="vPos" select="position()"/&gt; &lt;xsl:if test="position() &amp;gt; 1"&gt;&amp;#160;&lt;/xsl:if&gt; &lt;xsl:value-of select="concat(., ' ', ../following-sibling::*/*[position() = $vPos])"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>...when applied to your original XML:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Edited by XMLSpy® --&gt; &lt;Company&gt; &lt;EmployeeDetail&gt; &lt;Employees&gt; &lt;name&gt;Vishal&lt;/name&gt; &lt;name&gt;Ranvijay&lt;/name&gt; &lt;name&gt;Jagmit&lt;/name&gt; &lt;/Employees&gt; &lt;Employees&gt; &lt;name&gt;Verma&lt;/name&gt; &lt;name&gt;Sahay&lt;/name&gt; &lt;name&gt;Singh&lt;/name&gt; &lt;/Employees&gt; &lt;/EmployeeDetail&gt; &lt;/Company&gt; </code></pre> <p>...produces the output you desire:</p> <pre><code>Vishal Verma Ranvijay Sahay Jagmit Singh </code></pre> <p><strong>Explanation:</strong></p> <ul> <li>The first template matches the top-level element. Upon finding it, the XSLT processor is instructed to apply templates to all child elements of the first <code>&lt;Employees&gt;</code> element.</li> <li>The second template matches any element (which, given that there is only one other call to <code>&lt;xsl:apply-templates&gt;</code> in the XSLT, matches any child elements of the first <code>&lt;Employees&gt;</code> element). Upon finding such an element, the processor outputs the value of that current element, a space, and the value of the adjoining <code>&lt;name&gt;</code> element (meaning, the <code>&lt;name&gt;</code> element that exists at the same position as the current element, but within the context of the 2nd <code>&lt;Employees&gt;</code> element). <ul> <li>Note the use of <code>&lt;xsl:if test="position() &amp;gt; 1"&gt;&amp;#160;&lt;/xsl:if&gt;</code> - this outputs a space unless we've reached the last element (thus preventing trailing whitespace).</li> </ul></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload