Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Building on @Flynn's answer...</p> <p>If you have this template for the parent (not shown in your sample):</p> <pre><code>&lt;xsl:template match="row-parent"&gt; &lt;xsl:apply-templates select="row"&gt; &lt;xsl:sort select="name(*[1])" /&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; </code></pre> <p>Note that by selecting "row", instead of the default (all children, including text nodes), we avoid selecting text nodes that contain whitespace, and which are undesirable for our output.</p> <p>Then in order to add the section headings, the template for processing the children uses a conditional to see if this is the first row of its section:</p> <pre><code>&lt;xsl:template match="row"&gt; &lt;xsl:variable name="childName" select="name(*[1])"/&gt; &lt;!-- if this is the first row with an element child of this name --&gt; &lt;xsl:if test="not(preceding-sibling::row[name(*[1]) = $childName])"&gt; &lt;xsl:value-of select="concat('&amp;#10;', translate(substring($childName, 1, 1), $lower, $upper), substring($childName, 2), '&amp;#10;&amp;#10;')"/&gt; &lt;/xsl:if&gt; </code></pre> <p>Then output the data for each row of that group, with the formatting you want:</p> <pre><code> &lt;xsl:number level="any" count="row[name(*[1]) = $childName]" format=" 1. " from="row-parent"/&gt; &lt;xsl:value-of select="normalize-space(*[1])"/&gt; &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:template&gt; </code></pre> <p>As usual, $lower and $upper are defined at the top of the template (or stylesheet) as</p> <pre><code>&lt;xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/&gt; &lt;xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/&gt; </code></pre> <p>And make the stylesheet use the 'text' output method:</p> <pre><code>&lt;xsl:output method="text"/&gt; </code></pre> <p>The output of the above stylesheet on your input (within a <code>&lt;row-parent&gt;</code> wrapper) is:</p> <pre><code>Contact 1. some contact details 1 2. some contact details 2 Order 1. some order text 1 2. some order text 2 Payment 1. some payment text 1 </code></pre> <p>Alternatively, and more robustly, you can use <a href="http://www.jenitennison.com/xslt/grouping/muenchian.html" rel="nofollow">Muenchian grouping</a>: first to group the rows by child element name, then to (output the header for each group and) process all rows within the group.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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