distinct values of xml

E

Eugen

Hi All!
I need your help. I have XML with structure like this:
<dataset>
<node><category>C1</category><desc>D1</desc></node>
<node><category>C2</category><desc>D2</desc></node>
<node><category>C1</category><desc>D1</desc></node>
<node><category>C3</category><desc>D3</desc></node>
...
</dataset>

I want distinct <category> and <desc> values in the kind:

C1_D1
C2_D2
C3_D3


Thanks in advance for any help.
Eugene
 
J

Joris Gillis

Hi,

Tempore 10:08:36 said:
I want distinct <category> and <desc> values in the kind:
C1_D1
C2_D2
C3_D3

In XSLT 1.0 , it's common practice to approach this as a standard grouping problem, which in it's turns is easily tackled with the Muenchian technique.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" indent="yes"/>

<xsl:key name="node" match="node" use="concat(category,'_',desc)"/>

<xsl:template match="dataset">
<xsl:for-each select="node[generate-id()=
generate-id(key('node',concat(category,'_',desc))[1])]">
<xsl:value-of select="concat(category,'_',desc)"/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>


regards,
 
Joined
Jan 22, 2009
Messages
1
Reaction score
0
hi

Suppose if we have the xml like this..

<dataset value="1">
<node category="C1" desc="D1"></node>
<node category="C2" desc="D2"></node>
<node category="C1" desc="D1"></node>
<node category="C3" desc="D3"></node>
</dataset>

<dataset value="2">
<node category="C4" desc="D1"></node>
<node category="C4" desc="D2"></node>
<node category="C1" desc="D2"></node>
<node category="C3" desc="D3"></node>
</dataset>


I want the output like this...

Dataset = 1
C1_D1
C2_D2
C3_D3

Dataset = 2
C1_D2
C3_D3
C4_D1
C4_D2


please tell me the solution
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top