xml - XSL group by multiple conditions -
i want group items first element value, group results items other element value 'or' condition.
i'll try explain myself following xml example
<root> <request> <id_master>222</id_master> <id_x>1</id_x> <text>hey</text> </request> <response> <id_master>222</id_master> <id_y>1</id_y> <text>hello</text> </response> <request> <id_master>222</id_master> <id_y>1</id_y> <text>bye..</text> </request> <response> <id_master>222</id_master> <id_x>1</id_x> <text>bye</text> </response> <request> <id_master>222</id_master> <id_y>2</id_y> <text>i want ice..</text> </request> <response> <id_master>222</id_master> <id_x>2</id_x> <text>ok</text> </response> <request> <id_master>333</id_master> <id_y>5</id_y> <text>my name is</text> </request> <response> <id_master>333</id_master> <id_x>5</id_x> <text>alice</text> </response> <response> <id_master>333</id_master> <id_x>5</id_x> <text>i'm bob</text> </response> </root>
now, in above xml file have following ids : 1. id_master 2. id_x 3. id_y
first want group each block element id_master. group results id_x or id_y, output file should be:
<div> <h1>conversation id 222</h1> <p>[1] hey</p> <p>[1] hello</p> <p>[1] bye..</p> <p>[1] bye</p> </div> <div> <h1>conversation id 222</h1> <p>[2] want ice..</p> <p>[2] ok</p> </div> <div> <h1>conversation id 333</h1> <p>[2] name is</p> <p>[2] alice </p> <p>[2] i'm bob </p> </div>
i succeed group first part (group id_master) i'm getting trouble group second part...
here's got far :
<xsl:key name="key_group_by_master" match="*" use="id_master" /> <xsl:key name="key_group_by_slave" match="*" use="id_x or id_y" /> <!-- group master elements --> <xsl:for-each select="//*[generate-id(.)=generate-id(key('key_group_by_master', id_master)[1])]"> <div> <h1> conversation id <xsl:value-of select="id_master"/> </h1> <!-- i'm doing wrong here ?? need ... --> <xsl:for-each select="//*[generate-id(.)=generate-id(key('key_group_by_slave', id_x or id_y)[1])]"> <p> [<xsl:value-of select="id_x or id_y"/>] <xsl:value-of select="text"/> </p> </xsl:for-each> </div> </xsl:for-each>
using xslt 1.0
i define first key as
<xsl:key name="key_group_by_master" match="root/*" use="id_master"/>
and second needs concatenate master key slave key e.g.
<xsl:key name="slave" match="root/*" use="concat(id_master, '|', id_x | id_y)"/>
the inner for-each needs be
<xsl:for-each select="//*[generate-id(.)=generate-id(key('slave', concat(id_master, '|', id_x | id_y))[1])]">
that should long elements have either id_x
or id_y
not both.
Comments
Post a Comment