How to create one node from multiple nodes with same name using xsl?

pisagor

New Member
My XML structure is like\[code\]<Client> <Document> <service class="ABC"> <author name="x"/> <Details> ... </Details> </service> </Document> <Document> <service class="ABC"> <author name="x"/> <Details> ... </Details> </service> </Document> <Document> <service class="ABC"> <author name="x"/> <Details> ... </Details> </service> </Document>'</Client>\[/code\]I want it like\[code\]<Client> <Document> <service class="ABC"> <author name="x"/> <Details> ... </Details> </service> </Document> <Document> <service class="ABC"> <author name="x"/> <Details> ... </Details> </service> </Document> <Document> <service class="ABC"> <author name="x"/> <Details> ... </Details> </service> </Document>' <component> <service class="ABC"> <author name="x"/> </service> </component>'</Client>\[/code\]My xsl file contains\[code\]<xsl:template match="//v3:Client"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> <component> <service class=""> <xsl:apply-templates select="//v3:Client/v3:Document/v3:service/v3:author"/> </service> </component> </xsl:copy> </xsl:template> <xsl:template match="//v3:Client/v3:component/v3:service"> <xsl:element name="service" namespace="urn:hl7-org:v3"> <xsl:attribute name="class"> <xsl:value-of select="//v3:Client/v3:Document/v3:service/@class"/> </xsl:attribute> </xsl:element> </xsl:template>\[/code\]But its not giving desired output. Its giving output likeClient Document service class="ABC" author name="x" details ... details service Document Document service class="ABC" author name="x" details ... details service Document Document service class="ABC" author name="x" details ... details service Document component service class="" author name="x" service service class="" author name="x" service service class="" author name="x" service componentClientI'm new to xsl. Can anybody please help me to solve this problem?
 
Back
Top