Now I want to output all unique "Items" with @resp=abc. To just print all is no problem using: <ul> <xsl:for-each select="//overview/tools//item[contains(@resp,$role)]"> <xsl:apply-templates select="."/> </xsl:for-each> </ul>
But my desired outcome, removing duplicates, is: Item 1 Item 2 Item 3 Item 4 Item 5
I tried to compare each item's name with all preceding ones and skip the ones already existing by: <xsl:for-each select="//overview/tools//item[contains(@resp,$role) and not(text() = preceding::item[contains(@resp,$role)]/text())]"> <xsl:apply-templates select="."/> </xsl:for-each>
Msg#: 4354454 posted 1:21 pm on Aug 23, 2011 (gmt 0)
Hi Claes100, I suspect that XSLT is capable of this, but it won't be easy and I don't know the answer. My take on XSLT is "GIGO" - Garbage In, Garbage Out... When I'm transforming XML I do expect that the XML is going to be formatted and sorted and deduped and packaged up appropriately. The tools available in XSLT are not ideal for doing this kind of work.
Approaching the same problem, I'd be inclined to change the XML input rather than knit together complex XSLT templates to do data-manipulation jobs that XSLT isn't suited for. My language of preference is PHP, and I'm pretty sure I could dedupe the XML in about 20 lines of code, with 30 minutes of work, and the result would execute faster than the same thing done with XSLT.
Do you have control over the source of the XML?
If XSLT is your only option, there may be a way
Here's a snippet I found on the interwebz. It checks each node to see if any of the preceding ones have the same value