Need Help for Creating XSLT 2.0 for generating desired

XML Input :
<Study_Topic>
	<Topics>
		<PollutionName>
		  <K p="New1">AIR Pollution</K>
		  <K p="New2">WATER Pollution</K>
		</PollutionName>
		<Para_Ref L="Pollution">6.6</Para_Ref>
		<Para_Ref L="Pollution">22</Para_Ref>
		<PollutionName>
		  <K p="New3">Marine pollution</K>
		  <K p="New4">Soil pollution</K>
		  <K>Noise pollution</K>
		</PollutionName>
		<Para_Ref L="Pollution">22</Para_Ref>
		<Para_Ref L="Pollution">24</Para_Ref>
		<PollutionName>
		  <K p="New5">Biological contamination</K>
		  <K p="New6">Light Pollution</K>
		  <K>Power Pollution</K>
		</PollutionName>
		<Para_Ref L="Pollution">22</Para_Ref>
		<PollutionName>
		  <K p="New7">Environmental Pollution</K>
		  <K p="New8">Land Pollution</K>
		  <K>chemical Pollution</K>
		</PollutionName>
		<Para_Ref L="Pollution">6.6</Para_Ref>
		<Para_Ref L="Pollution">22</Para_Ref>
		<Para_Ref L="Pollution">24</Para_Ref>
		<PollutionName>
		  <K>World Pollution</K>
		</PollutionName>
		<Para_Ref L="Pollution">38</Para_Ref>
	</Topics>
</Study_Topic>

Open in new window


Desired Output:
<field TopicName>
       <div class="PollutionName">
			<p> AIR Pollution : WATER Pollution <PageNo>Page No.(6.6, 22) </PageNo></p>
			<p>Marine pollution : Soil pollution : Noise pollution <PageNo>Page No.(22, 24)</PageNo></p>
			<p>Biological contamination : Light Pollution : Power Pollution <PageNo>Page No.(22)</PageNo></p>
			<p>Environmental Pollution : Land Pollution : Chemical Pollution <PageNo>Page No.(6.6, 22, 24)</PageNo></p>
			<p>World Pollution<PageNo>Page No.(38)</PageNo></p>
	   </div>
</field>

Open in new window


Could anyone help us out with XSLT 2.0 Code for generating the xml output?

Any help is appreciated. Thanks in advance.
Mahesh SawarkarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
This seems like a typical grouping case, try this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
   <xsl:output indent="yes"></xsl:output>
   
    <xsl:template match="/Study_Topic">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="Topics">
        <field_TopicName>
            <div class="PollutionName">
                <xsl:for-each-group select="*" group-starting-with="PollutionName">
                    <p>
                        <xsl:value-of select="string-join(K, ' : ')"/>
                        <xsl:text> </xsl:text>
                        <PageNo>
                            <xsl:text>Page No.(</xsl:text>
                            <xsl:value-of select="string-join(current-group()/self::Para_Ref, ', ')"/>
                            <xsl:text>)</xsl:text>
                        </PageNo>
                    </p>
                </xsl:for-each-group>
            </div>
        </field_TopicName>
    </xsl:template>
    
    
</xsl:stylesheet>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mahesh SawarkarAuthor Commented:
Thank You Geert Bormans.
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.