Re: [xsl] Group or sort?

Subject: Re: [xsl] Group or sort?
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Thu, 14 Oct 2010 23:31:39 +0200
On 14.10.2010 23:10, charlieo0@xxxxxxxxxxx wrote:
I seem to have a constant problem with getting the correct results with grouping. I have a problem I could use help with that is either a sort or grouping problem. Possibly both.

Or rather none of them. Here's a solution using just apply-templates:


  <xsl:template match="fgc_list">
    <xsl:copy>
      <xsl:apply-templates select="fnc"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="fnc">
    <xsl:copy-of select="." />
    <xsl:copy-of select="../figure[@parent-id eq current()/@id]" />
  </xsl:template>


Desired Result:

<fgc_list>
   <fnc code="01" id="fgc1"/>
   <fnc code="0101" id="fgc1.1" parent-id="fgc1"/>
   <figure figid="1" parent-id="fgc1.1"/>
   <figure figid="2" parent-id="fgc1.1"/>
   <fnc code="02" id="fgc2"/>
   <fnc code="0201" id="fgc2.1" parent-id="fgc2"/>
   <fnc code="020101" id="fgc2.1.1" parent-id="fgc2.1"/>
   <figure figid="3" parent-id="fgc2.1"/>

The proposed solution inserts figure3 at another position than specified: just after its parent fgc2.1, rather than after fgc2.1.1. Is this ok? I couldn't devise a rule that inserts figure4 immediately after its parent fgc2.1.2, while figure3 won't be inserted immediately after its parent but after the first of fgc2.1's two children.


   <fnc code="020102" id="fgc2.1.2" parent-id="fgc2.1"/>
   <figure figid="4" parent-id="fgc2.1.2"/>
</fgc_list>

I need the<fnc> element to remain in the current order, but insert the sibling<figure> elements with the attribute "parent-id" where that value matches the "id" attribute of the preceding<fnc>.

Proposed solution seems to be in accordance with this rule.


-Gerrit



Charles

Current Thread