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
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:
- How can I convert UTF-16 file to UTF-8?Best solution by Stack Overflow
- How can I convert Matlab code to c#?Best solution by Stack Overflow
- How to convert build.xml to maven pom.xml file?Best solution by Stack Overflow
- How can I convert the query from SQL to LINQ?Best solution by Stack Overflow
- How Can I Create an XML to Create a Menu?Best solution by Drupal Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.