[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] for-each-group - only get elements in each group


Subject: Re: [xsl] for-each-group - only get elements in each group
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Jan 2016 17:43:19 -0000

Rick Quatro rick@xxxxxxxxxxxxxx wrote:

<Cases>
   <Story>
     <Category>Category1</Category>
     <Case>Case1</Case>
     <Category>Category1</Category>
     <Case>Case2</Case>
     <Category>Category1</Category>
     <Case>Case3</Case>
     <Category>Category1</Category>
     <Case>Case4</Case>
     <Category>Category2</Category>
     <Case>Case5</Case>
     <Category>Category2</Category>
     <Case>Case6</Case>
     <Category>Category2</Category>
     <Case>Case7</Case>
     <Category>Category2</Category>
     <Case>Case8</Case>
   </Story>
</Cases>

Here you have only one "Story" element with several "Category" and "Case" child elements.


I want to group on each unique <Category> element and then only include the
<Case> elements for each <Category>.

How do you relate a "Case" to a "Category"? Because they are direct siblings?



     <xsl:template match="Cases">
         <xsl:for-each-group select="Story" group-by="Category">
             <category><xsl:copy-of
select="current-grouping-key()"/></category>
             <xsl:apply-templates select="Case"/>
         </xsl:for-each-group>

You group the single "Story" by the "Category" child and then apply-templates to all "Case" child of the "Story".



Current Thread