![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] 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? |
| |
| |||
| Try this stylesheet. Note it uses version2.0, so may not be compatible with some browsers. <xsl:stylesheet version="2.0" xmlns sl="http://www.w3.org/1999/XSL/Transform"><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> |
![]() |
| Thread Tools | |
| Display Modes | |
| |