Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL grouping xml by element
    primarykey
    data
    text
    <p>Im working with XSLT1.0 (Processor can't handle 2.0) and have a problem trying to group the output of an xml structure:</p> <p>&lt;row&gt;<br> &lt;order&gt;<br> &lt;text&gt; some order text 1 <br> &lt;/text&gt;<br> &lt;/order><br> &lt;/row><br></p> <p>&lt;row&gt;<br> &lt;payment&gt;<br> &lt;text&gt; some payment text 1 <br> &lt;/text&gt;<br> &lt;/payment><br> &lt;/row><br></p> <p>&lt;row&gt;<br> &lt;order&gt;<br> &lt;text&gt; some order text 2 <br> &lt;/text&gt;<br> &lt;/order><br> &lt;/row><br></p> <p>&lt;row&gt;<br> &lt;contact&gt;<br> &lt;text&gt; some contact details 1 <br> &lt;/text&gt;<br> &lt;/contact><br> &lt;/row><br></p> <p>&lt;row&gt;<br> &lt;contact&gt;<br> &lt;text&gt; some contact details 2 <br> &lt;/text&gt;<br> &lt;/contact><br> &lt;/row><br></p> <p>Today we select all rows and call apply template for each (each type has its own template that writes out its body), that creates an output like:</p> <p>Order: some order text1<br> Order: some order text2<br> Payment: some payment text1<br> Contact: some contact details1 <br> Contact: some contact details2 <br></p> <p>But what I would like is to (in XSLT 1.0) to group the output so that:</p> <p>Order</p> <ol> <li>some order text1 </li> <li>some order text2</li> </ol> <p>Payment</p> <ol> <li>some payment text1</li> </ol> <p>Contact</p> <ol> <li>some contact details1 </li> <li>some contact details2</li> </ol> <p>Obviously there are many other element types than order,payment and contact involved here so selecting by explicit element names is not a solution.</p> <p>EDIT</p> <p>Ty, some great answers, how would the Muenchian grouping solution change if I had a structure of say</p> <pre><code>&lt;customers&gt; &lt;person&gt; &lt;row&gt;....&lt;/row&gt; (row is same as above) &lt;row&gt;....&lt;/row&gt; &lt;/person&gt; &lt;person&gt; &lt;row&gt;....&lt;/row&gt; &lt;row&gt;....&lt;/row&gt; &lt;row&gt;....&lt;/row&gt; &lt;/person&gt; </code></pre> <p>Then the key:</p> <pre><code> &lt;xsl:key name="type" match="row/*" use="local-name()"/&gt; </code></pre> <p>Would select all rows across all persons which is not what I wanted. Thanks for great responses too.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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