XSLT: Unique nodes only based on specific attribute?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a question using XSLT in C# (it is a XSLT question). I use a XPathDocument to load my XML, then a XslCompiledTransform to load my XSLT and then I apply the Transform method and it works fine. But I have a question for what I am trying to transform.
I determine a unique ID based on 3 nodes: FilmCode (optional, highest priority), if it doesnt exist I use Title (also optional) and if it also doesnt exist I use TitleShort (which always exists). I am trying to find all Films that have a unique ID
(ID based on the rule I explaine). Here is my XSLT:
<pre class="prettyprint <xsl:for-each select="Films/Film
<Movie>
<xsl:attribute name="Id
<xsl:choose>
<!-- FilmCode is optional -->
<xsl:when test="FilmCode
<xsl:value-of select="FilmCode"/>
</xsl:when>
<!-- Title is optional -->
<xsl:when test="Title
<xsl:value-of select="Title"/>
</xsl:when>
<!-- TitleShort is required -->
<xsl:otherwise>
<xsl:value-of select="TitleShort"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>

...

</Movie>
</xsl:for-each>[/code]
My problem is I not sure how to avoid duplicates. I only want the first Film parsed with a specific ID (I want to ignore duplicates that occur after). It is was only 1 field it would be easy but because of my "rule" to generate the ID, I cant figure it
out.
Thanks


View the full article
 
Back
Top