1

Topic: Help with XSLT-transformation

Is such xml:

<? xml version = "1.0" encoding = "UTF-8"?>
<? xml-stylesheet type ='text/xsl ' href ='test.xsl '?>
<service>
<request-types>
<type id = "1" caption = "value 1"/>
<type id = "2" caption = "value 2"/>
<type id = "3" caption = "value 3"/>
<type id = "4" caption = "value 4"/>
<type id = "5" caption = "value 5"/>
</request-types>
<requests>
<request type = "3" client-name = "client 1"> some text 1 </request>
<request type = "4" client-name = "client 2"> some text 2 </request>
<request type = "3" client-name = "client 3"> some text 3 </request>
<request type = "4" client-name = "client 4"> some text 4 </request>
<request type = "4" client-name = "client 5"> some text 5 </request>
<request type = "5" client-name = "client 6"> some text 6 </request>
</requests>
</service>

On an output by means of XSLT-transformation it is necessary to receive such xml:

<request-stats>
<request type-caption = "value 1" count = "0"/>
<request type-caption = "value 2" count = "0"/>
<request type-caption = "value 3" count = "2"/>
<request type-caption = "value 4" count = "3"/>
<request type-caption = "value 5" count = "1"/>
</request-stats>

2

Re: Help with XSLT-transformation

<? xml version = "1.0" encoding = "utf-8"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:key name = "key" match = "service/requests/request / type" use = "."/>
<xsl:template match = "/">
<request-stats>
<xsl:for-each select = "service/request-types/type">
<xsl:variable name = "caption" select = "caption"/>
<xsl:variable name = "count" select = "count (key (' key ', @id))"/>
<request type-caption = "{$ caption}" count = "{$ count}"/>
</xsl:for-each>
</request-stats>
</xsl:template>
</xsl:stylesheet>