sorry about that, reply was nonsense:-) will post again when awake...
David
On 20 January 2016 at 17:35, Rick Quatro rick(_at_)rickquatro(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Hi, I have this XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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>
I want to group on each unique <Category> element and then only include the
<Case> elements for each <Category>. Here is what I need:
<?xml version="1.0" encoding="UTF-8"?>
<cases>
<category>Category1</category>
<Case>Case1</Case>
<Case>Case2</Case>
<Case>Case3</Case>
<Case>Case4</Case>
<category>Category2</category>
<Case>Case5</Case>
<Case>Case6</Case>
<Case>Case7</Case>
<Case>Case8</Case>
</cases>
However, I am getting this:
<?xml version="1.0" encoding="UTF-8"?>
<cases>
<category>Category1</category>
<Case>Case1</Case>
<Case>Case2</Case>
<Case>Case3</Case>
<Case>Case4</Case>
<Case>Case5</Case>
<Case>Case6</Case>
<Case>Case7</Case>
<Case>Case8</Case>
<category>Category2</category>
<Case>Case1</Case>
<Case>Case2</Case>
<Case>Case3</Case>
<Case>Case4</Case>
<Case>Case5</Case>
<Case>Case6</Case>
<Case>Case7</Case>
<Case>Case8</Case>
</cases>
Here is my 2.0 stylesheet. Thanks in advance for any help. -Rick
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<cases><xsl:apply-templates select="Cases"/></cases>
</xsl:template>
<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>
</xsl:template>
<xsl:template match="Case">
<Case><xsl:value-of select="."/></Case>
</xsl:template>
</xsl:stylesheet>
--
http://dpcarlisle.blogspot.com/
--~----------------------------------------------------------------
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
--~--