Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Join in XSLT : too many copies

From: robertocarota@-----.--
To: 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>


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent