![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Join in XSLT : too many copies Join in XSLT : too many copiesTo: NULL Date: 5/3/2004 1:41:00 AM I am trying to write a XSLT file to transform this XML <?xml version="1.0" encoding="UTF-8"?><bib><book year="1999"><title>A title</title><author><last>Smith</last><first>John</first></author></book><book year="2003"><title>Another title</title><author><last>Lastname</last><first>Mark</first></author><author><last>Smith</last><first>John</first></author><author><last>Smith</last><first>Mary</first></author><author><last>Smith</last><first>Jack</first></author></book><book year="2003"><title>The third title</title><author><last>Smith</last><first>John</first></author><author><last>Doe</last><first>Paul</first></author></book></bib into this <?xml version="1.0" encoding="UTF-8"?><bib><book year="2003"><title>Another title</title><author><last>Lastname</last><first>Mark</first></author><author><last>Smith</last><first>John</first></author><author><last>Smith</last><first>Mary</first></author><author><last>Smith</last><first>Jack</first></author></book></bib --------------------------------------------------------------------------------------- The query I want to write is "copy all the books which have at least two authors with the same <last> but with different <first> The problem is that I can't obtain just a single copy for each book, but I obtain as many copy as the matching authors How can I solve this --------------------------------------------------------------------------------------- The query I have written is <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/><xsl:template match="/"><bib><xsl:apply-templates/></bib></xsl:template><xsl:template match="bib/book"><xsl:variable name="contesto" select="."/><xsl:for-each select="author"><xsl:variable name="first1" select="first/text()"/><xsl:variable name="last1" select="last/text()"/><xsl:for-each select="../author"><xsl:variable name="first2" select="first/text()"/><xsl:variable name="last2" select="last/text()"/><xsl:if test="$first1!=$first2 and $last1=$last2"><xsl:copy-of select="$contesto"/></xsl:if></xsl:for-each></xsl:for-each></xsl:template></xsl:stylesheet> | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
