xsl-list
[Top] [All Lists]

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

2016-01-20 11:43:33
Rick Quatro rick(_at_)rickquatro(_dot_)com 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".
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>