xml - XSLT - how to group output by common child element value in XSLT 2.0 -


i have xml file below may have multiple records common child element so:

<person>   <name>alice</name>   <account>001</account> </person> <person>   <name>alice</name>   <account>002</account> </person> 

how transform below using xslt 2.0?

<person>   <name>alice</name>   <account>001,002</account> </person> 

i'm new xslt please excuse potentially novice question. guidance appreciated here. in advance.

you can use for-each-group group person elements, , separator attribute on value-of build comma-separated value:

<xsl:for-each-group select="person" group-by="name">   <person>     <xsl:sequence select="name" /><!-- copy name element -->     <account>       <xsl:value-of select="current-group()/account" separator="," />     </account>   </person> </xsl:for-each-group> 

(assuming current context node parent of person elements - if not you'll have adjust for-each-group select expression appropriately)


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -