Okay, I have reached a complete mental block on trying to get this to work and was wondering if anyone else might be able to get their head around it. I have the following structure to HTML.
<?xml version="1.0" encoding="utf-8"?>
<root>
<listing>
<name>Frank Spencer</name>
<dob>2010-09-01</dob>
<details>
<firmname>Scotts</firmname>
<address>Blah Blah</address>
<businessname>Scotts</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
<details>
<firmname>Scotts</firmname>
<address>Blah Blah</address>
<businessname>Wilson and Son</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
<details>
<firmname>Wilson and Son</firmname>
<address>Blah Blah</address>
<businessname>Brudebakers</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
<details>
<firmname>Carnage and Co.</firmname>
<address>Blah Blah</address>
<businessname>Brudebakers</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
</listing>
<listing>
<name>Han Solo</name>
<dob>2010-09-01</dob>
<details>
<firmname>Independent trading</firmname>
<address>Blah Blah</address>
<businessname>Fugitive freight</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
<details>
<firmname>Scotts</firmname>
<address>Blah Blah</address>
<businessname>Wilson and Son</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
<details>
<firmname>Wilson and Son</firmname>
<address>Blah Blah</address>
<businessname>Scotts</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
<details>
<firmname>Carnage and Co.</firmname>
<address>Blah Blah</address>
<businessname>Brudebakers</businessname>
<businessaddress>Blahdeblah</businessaddress>
</details>
</listing>
</root>
With the following XSLT.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:param name="searchName">Wilson</xsl:param>
<xsl:param name="searchName2"></xsl:param>
<xsl:variable name="Uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="Lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:template match="/">
<xsl:for-each select="root/listing">
<p>Name: <xsl:value-of select="name"/></p>
<p>DOB: <xsl:value-of select="dob" /></p>
<xsl:for-each select="details[not(firmname=following::root/listing/details/firmname) and not(businessname=following::root/listing/details/businessname) or not(firmname=following::root/listing/details/businessname) or not(businessname=following::root/listing/details/firmname)]">
<xsl:choose>
<xsl:when test="contains(translate(firmname,$Uppercase,$Lowercase), translate($searchName,$Uppercase,$Lowercase)) and contains(translate(businessname,$Uppercase,$Lowercase), translate($searchName,$Uppercase,$Lowercase)) and not($searchName = '')">
(This individual has previously worked at:
<xsl:value-of select="firmname" />
</xsl:when>
<xsl:when test="contains(translate(businessname,$Uppercase,$Lowercase), translate($searchName,$Uppercase,$Lowercase)) and not(contains(translate(firmname,$Uppercase,$Lowercase), translate($searchName,$Uppercase,$Lowercase))) and not($searchName = '')">
(This individual has previously worked at:
<xsl:value-of select="businessname" />)
</xsl:when>
<xsl:when test="contains(translate(firmname,$Uppercase,$Lowercase), translate($searchName,$Uppercase,$Lowercase)) and not(contains(translate(businessname,$Uppercase,$Lowercase), translate($searchName,$Uppercase,$Lowercase))) and not($searchName = '')">
(This individual has previously worked at:
<xsl:value-of select="firmname" />)<br/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
What I want is to get a list of the firms which contain the search term. But what I get is:
Name: Frank Spencer DOB: 2010-09-01 (This individual has previously worked at: Wilson and Son) (This individual has previously worked at: Wilson and Son) Name: Han Solo DOB: 2010-09-01 (This individual has previously worked at: Wilson and Son) (This individual has previously worked at: Wilson and Son)
The xslt should look at both firmname and businessname and then if it finds a match with the contains it should print out only one reference. But I can’t seem to get it to work. Has anyone got any solutions/suggestions? The ideal outcome is.
<body>
<p>Name: Frank Spencer</p>
<p>DOB: 2010-09-01</p>
<p>(This individual has previously worked at: Wilson and Son)</p>
<p>Name: Han Solo</p>
<p>DOB: 2010-09-01</p>
<p>(This individual has previously worked at: Wilson and Son)</p>
</body>
Is it what you looking for?
Output: