How to merge 2 xml docs with xslt?

Can XSLT convert this XML?

  • Source XML: <books> <author> <fname>William</fname> <lname>Shakespeare</lame> <bookName>Merchant of Venice</bookName> <bookRank>One</bookRank> </author> <author> <fname>William</fname> <lname>Shakespeare</lame> <bookName>As You Like It</bookName> <bookRank>Two</bookRank> </author> </books> Needs to be transformed to: <books> <author> <fname>William</fname> <lname>Shakespeare</lname> <books> <book> <bookName>Merchant of Venice</bookName> <bookRank>One</bookRank> </book> <book> <bookName>As You Like It</bookName> <bookRank>Two</bookRank> </book> </books> </author> </books> Can you give me the XSL for this transformation?

  • Answer:

    Try this stylesheet. Note it uses version2.0, so may not be compatible with some browsers. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/… <xsl:output indent="yes"/> <xsl:template match="books"> <books> <xsl:for-each-group select="author" group-by="concat(fname,'/',lname)"> <author> <xsl:copy-of select="fname,lname"/> <books> <xsl:for-each select="current-group()"> <book> <xsl:copy-of select="bookName,bookRank"/> </book> </xsl:for-each> </books> </author> </xsl:for-each-group> </books> </xsl:template> </xsl:stylesheet>

mindy m at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

try posting what you have already done! this looks like homework! it's also the exercise in the last xsl book I read!

jake cigarâ„¢ is retired

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.