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

[xsl] xsl:for-each-group question


Subject: [xsl] xsl:for-each-group question
From: "Markus Ohlenroth markus.ohlenroth@xxxxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 27 Jan 2016 13:15:17 -0000

Unsing xsl 2.0

 

The below xsl changes the below xml with a list of flat <P/> nodes into
groups based on values in subnodes of <p/>

The result achived with the xsl below is what I want.

 

But what I cannot figure out is:

 

What values must the "select" argument and/or the "group-starting-with"
arguments have in my example

so that the resulting current-group() nodes are <p/> nodes (i.e. the parent
node) instead of <rStyle/> nodes.

 

I cannot achieve the wanted grouping with the resulting current-group()
nodes being <p/> nodes.

I can only achieve the wanted grouping with the resulting current-group()
nodes being <rStyle/> nodes.

 

Thank you for any help.

Kind regards

Markus

 

XML INPUT File:

<Root>

                <p>

                               <rStyle val="Lemma"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

                <p>

                               <rStyle val="Lemma"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

                <p>

                               <rStyle val="Lemma"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

                <p>

                               <rStyle val="description"/>

                </p>

</Root>

 

################ XSL Processing FILE extract
###################################

 

<xsl:template match="Root">

                               <xsl:copy>

 
<xsl:for-each-group select="p/rStyle"
group-starting-with="p/rStyle[@val='Lemma']">

                                                               <service>

<!--                                                                       

This is what I really want as current-group()

<xsl:copy-of select="current-group()/parent::node() "/> 

-->

 
<xsl:copy-of select="current-group()"/>

                                                               </service>

                                               </xsl:for-each-group>

                               </xsl:copy>

                </xsl:template>

 

 

################ Desired Result XML snippet
###################################

<service>

                               <p>

                                               <rStyle val="Lemma"/>

                               </p>

                               <p>

                                               <rStyle val="description"/>

                               </p>

                               <p>

                                               <rStyle val="description"/>

                               </p>

                </service>

################ Current Result XML snippet
#########################################

<service >

                               <rStyle val="Lemma"/>

                               <rStyle val="description"/>

                               <rStyle val="description"/>

</service>


Current Thread
Keywords