Hi there
I have a questing about XSLT.
I am making a website on Sitecore CMS, and some of the pages have to show a list of articles. That's not a problem.
Every articlelist can be 'tagged' with one or more tags, and the same for every article. Let's say that I have an articlelist that have been tagged with 'Wordpress'. Then I only want to show articles who also have been tagged with 'Wordpress' of course. That also all right.
But now my problem: If an articlelist is tagged with more than one tag, and an article is tagged with the same tags, then the article will be shown several times, because my XSLT recognizes the tags more than one time.
An example: I have an articlelist with tags 'A' and 'B'. Then I have four articles:
- Article 1 (Tags: 'A')
- Article 2 (Tags: 'A' and 'B')
- Article 3 (Tags: 'B' and 'C')
- Article 4 (Tags: 'D')
Now in my list I want to show all the articles with the same tags as my articlelist. That will be Article 1, Article 2 and Article 3.
My code does that, but because of the two same tags on the list and Article 2, Article 2 shows up two times, and thats not good.
I have some of my code down below:
<xsl:template match="*">
<xsl:variable name="ids" select="concat(sc:fld('tags',$sc_currentitem),'|')"/>
<xsl:call-template name="PrintTitles">
<xsl:with-param name="ids" select="$ids"/>
<!-- $sc_currentitem is the item that im currently standing on -->
<xsl:with-param name="item" select="$sc_currentitem" />
</xsl:call-template>
</xsl:template>
<xsl:template name="PrintTitles">
<xsl:param name="ids"/>
<xsl:param name="item"/>
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
<xsl:apply-templates select="
msxml:node-set($item)/item[
contains(fields/field[@key='tags'], $itm_id)
]
" mode="insure">
<xsl:with-param name="itm_id" select="$itm_id" />
</xsl:apply-templates>
<xsl:call-template name="PrintTitles">
<xsl:with-param name="ids" select="substring-after($ids, '|')"/>
<xsl:with-param name="item" select="$item" />
</xsl:call-template>
</xsl:template>
<xsl:template match="item" mode="insure">
<xsl:param name="itm_id" />
<!-- ... -->
</xsl:template>
Heres my XML from one of the articlelists:
<item name="Artikelliste" key="artikelliste" id="{92BC787F-C935-4EE7-9D41-AEAF67C9CC06}" tid="{D0C4BD18-E64E-4470-B483-4F33BD50F25F}" mid="{00000000-0000-0000-0000-000000000000}" sortorder="200" language="en" version="1" template="artikelliste" parentid="{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}">
<fields>
<field tfid="{25BED78C-4957-4165-998A-CA1B52F67497}" key="__created" type="datetime">
<content></content>
</field>
<field tfid="{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}" key="__updated by" type="text">
<content></content>
</field>
<field tfid="{234DC975-40DA-472B-B315-796C0FAA8D53}" key="meta title" type="Single-Line Text">
<content></content>
</field>
<field tfid="{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}" key="__updated" type="datetime">
<content></content>
</field>
<field tfid="{72BA1931-236F-4279-8E39-8AC60D33408F}" key="navn i menuen" type="Single-Line Text">
<content></content>
</field>
<field tfid="{8CDC337E-A112-42FB-BBB4-4143751E123F}" key="__revision" type="text">
<content></content>
</field>
<field tfid="{9683EB7C-DE18-472D-B058-562573FAE23D}" key="titel" type="Single-Line Text">
<content></content>
</field>
<field tfid="{001DD393-96C5-490B-924A-B0F25CD9EFD8}" key="__lock" type="memo">
<content></content>
</field>
<field tfid="{93871141-7CB3-472E-9A75-6237A3BCC0F6}" key="tekstindhold" type="Rich Text">
<content></content>
</field>
<field tfid="{9C13A0D7-2B01-4BB6-B35F-9B073ABEDDF3}" key="relaterede sider" type="Treelist">
<content></content>
</field>
<field tfid="{92EB3D7A-DA52-496F-ABC1-6869E3B14551}" key="tags" type="Treelist">
<content></content>
</field>
<field tfid="{2E4FD6E4-83FE-4592-9327-FEC102F817C9}" key="billedetop" type="Image">
<content></content>
</field>
<field tfid="{7C67F2F2-3577-4466-B170-552E463ADD57}" key="source" type="Droptree">
<content></content>
</field>
<field tfid="{C38B9B42-D81D-42ED-A56E-4DBA6FD92D4A}" key="antal artikler" type="Number">
<content></content>
</field>
<field tfid="{5E6D670A-2DD4-4088-8E82-FFD920CEFD9C}" key="alle artikler link" type="Internal Link">
<content></content>
</field>
<field tfid="{BA3F86A2-4A1C-4D78-B63D-91C2779C1B5E}" key="__sortorder" type="text">
<content></content>
</field>
<field tfid="{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}" key="__renderings" type="layout">
<content></content>
</field>
<field tfid="{DEC8D2D5-E3CF-48B6-A653-8E69E2716641}" key="__security" type="security">
<content></content>
</field>
<field tfid="{A0CB3965-8884-4C7A-8815-B6B2E5CED162}" key="__editors" type="TreelistEx">
<content></content>
</field>
</fields>
<item name="HP artikel" key="hp artikel" id="{94A742D5-D446-4170-8AF8-099561F57CC4}" tid="{303D39D0-278E-4034-8420-E19A3DEC3298}" mid="{00000000-0000-0000-0000-000000000000}" sortorder="100" language="en" version="1" template="artikel" parentid="{92BC787F-C935-4EE7-9D41-AEAF67C9CC06}">
<fields>
<field tfid="{25BED78C-4957-4165-998A-CA1B52F67497}" key="__created" type="datetime">
<content></content>
</field>
<field tfid="{8CDC337E-A112-42FB-BBB4-4143751E123F}" key="__revision" type="text">
<content></content>
</field>
<field tfid="{234DC975-40DA-472B-B315-796C0FAA8D53}" key="meta title" type="Single-Line Text">
<content></content>
</field>
<field tfid="{9683EB7C-DE18-472D-B058-562573FAE23D}" key="titel" type="Single-Line Text">
<content></content>
</field>
<field tfid="{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}" key="__updated by" type="text">
<content></content>
</field>
<field tfid="{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}" key="__updated" type="datetime">
<content></content>
</field>
<field tfid="{001DD393-96C5-490B-924A-B0F25CD9EFD8}" key="__lock" type="memo">
<content></content>
</field>
<field tfid="{93871141-7CB3-472E-9A75-6237A3BCC0F6}" key="tekstindhold" type="Rich Text">
<content></content>
</field>
<field tfid="{F1F0A054-010A-41F1-B0AC-D0D658727181}" key="teaser" type="Multi-Line Text">
<content></content>
</field>
<field tfid="{476E11CA-A205-48B2-9520-A0C3D954B281}" key="e-mail" type="Single-Line Text">
<content></content>
</field>
<field tfid="{30A47651-E207-4042-95CC-67C00696EA6F}" key="skrevet af" type="Single-Line Text">
<content></content>
</field>
<field tfid="{12DE369B-E308-4F24-A617-CD426CF0A29A}" key="relateret information" type="Treelist">
<content></content>
</field>
<field tfid="{311C5D67-66FB-422A-84CC-3312EF8A6B64}" key="medarbejder" type="Multilist">
<content></content>
</field>
<field tfid="{08D9129F-0967-4718-A158-2B8CC322D1E7}" key="tags" type="Treelist">
<content></content>
</field>
<field tfid="{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}" key="__renderings" type="layout">
<content></content>
</field>
</fields>
</item>
<item name="Microsoft artikel" key="microsoft artikel" id="{7AF63885-8BA4-4619-9654-12B3865500D0}" tid="{303D39D0-278E-4034-8420-E19A3DEC3298}" mid="{00000000-0000-0000-0000-000000000000}" sortorder="100" language="en" version="1" template="artikel" parentid="{92BC787F-C935-4EE7-9D41-AEAF67C9CC06}">
<fields>
<field tfid="{25BED78C-4957-4165-998A-CA1B52F67497}" key="__created" type="datetime">
<content></content>
</field>
<field tfid="{8CDC337E-A112-42FB-BBB4-4143751E123F}" key="__revision" type="text">
<content></content>
</field>
<field tfid="{234DC975-40DA-472B-B315-796C0FAA8D53}" key="meta title" type="Single-Line Text">
<content></content>
</field>
<field tfid="{9683EB7C-DE18-472D-B058-562573FAE23D}" key="titel" type="Single-Line Text">
<content></content>
</field>
<field tfid="{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}" key="__updated by" type="text">
<content></content>
</field>
<field tfid="{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}" key="__updated" type="datetime">
<content></content>
</field>
<field tfid="{001DD393-96C5-490B-924A-B0F25CD9EFD8}" key="__lock" type="memo">
<content></content>
</field>
<field tfid="{93871141-7CB3-472E-9A75-6237A3BCC0F6}" key="tekstindhold" type="Rich Text">
<content></content>
</field>
<field tfid="{F1F0A054-010A-41F1-B0AC-D0D658727181}" key="teaser" type="Multi-Line Text">
<content></content>
</field>
<field tfid="{476E11CA-A205-48B2-9520-A0C3D954B281}" key="e-mail" type="Single-Line Text">
<content></content>
</field>
<field tfid="{30A47651-E207-4042-95CC-67C00696EA6F}" key="skrevet af" type="Single-Line Text">
<content></content>
</field>
<field tfid="{2E4FD6E4-83FE-4592-9327-FEC102F817C9}" key="billedetop" type="Image">
<content></content>
</field>
<field tfid="{12DE369B-E308-4F24-A617-CD426CF0A29A}" key="relateret information" type="Treelist">
<content></content>
</field>
<field tfid="{311C5D67-66FB-422A-84CC-3312EF8A6B64}" key="medarbejder" type="Multilist">
<content></content>
</field>
<field tfid="{B61C079A-0B97-4CC0-BB9F-22E7B49D57F9}" key="relaterede sider" type="Treelist">
<content></content>
</field>
<field tfid="{08D9129F-0967-4718-A158-2B8CC322D1E7}" key="tags" type="Treelist">
<content></content>
</field>
<field tfid="{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}" key="__renderings" type="layout">
<content></content>
</field>
</fields>
</item>
<item name="New Artikel" key="new artikel" id="{91D6625E-F0C4-43C0-A990-078536C1989C}" tid="{303D39D0-278E-4034-8420-E19A3DEC3298}" mid="{00000000-0000-0000-0000-000000000000}" sortorder="100" language="en" version="2" template="artikel" parentid="{92BC787F-C935-4EE7-9D41-AEAF67C9CC06}">
<fields>
<field tfid="{25BED78C-4957-4165-998A-CA1B52F67497}" key="__created" type="datetime">
<content></content>
</field>
<field tfid="{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}" key="__updated by" type="text">
<content></content>
</field>
<field tfid="{5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}" key="__created by" type="text">
<content></content>
</field>
<field tfid="{234DC975-40DA-472B-B315-796C0FAA8D53}" key="meta title" type="Single-Line Text">
<content></content>
</field>
<field tfid="{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}" key="__updated" type="datetime">
<content></content>
</field>
<field tfid="{8CDC337E-A112-42FB-BBB4-4143751E123F}" key="__revision" type="text">
<content></content>
</field>
<field tfid="{9683EB7C-DE18-472D-B058-562573FAE23D}" key="titel" type="Single-Line Text">
<content></content>
</field>
<field tfid="{3E431DE1-525E-47A3-B6B0-1CCBEC3A8C98}" key="__workflow state" type="reference">
<content></content>
</field>
<field tfid="{001DD393-96C5-490B-924A-B0F25CD9EFD8}" key="__lock" type="memo">
<content></content>
</field>
<field tfid="{93871141-7CB3-472E-9A75-6237A3BCC0F6}" key="tekstindhold" type="Rich Text">
<content></content>
</field>
<field tfid="{F1F0A054-010A-41F1-B0AC-D0D658727181}" key="teaser" type="Multi-Line Text">
<content></content>
</field>
<field tfid="{C8F93AFE-BFD4-4E8F-9C61-152559854661}" key="__valid from" type="datetime">
<content></content>
</field>
<field tfid="{08D9129F-0967-4718-A158-2B8CC322D1E7}" key="tags" type="Treelist">
<content></content>
</field>
<field tfid="{12DE369B-E308-4F24-A617-CD426CF0A29A}" key="relateret information" type="Treelist">
<content></content>
</field>
</fields>
</item>
<item name="NY" key="ny" id="{F54BC47C-8D7D-4017-BA39-31AAFCD92042}" tid="{303D39D0-278E-4034-8420-E19A3DEC3298}" mid="{00000000-0000-0000-0000-000000000000}" sortorder="100" language="en" version="1" template="artikel" parentid="{92BC787F-C935-4EE7-9D41-AEAF67C9CC06}">
<fields>
<field tfid="{25BED78C-4957-4165-998A-CA1B52F67497}" key="__created" type="datetime">
<content></content>
</field>
<field tfid="{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}" key="__updated by" type="text">
<content></content>
</field>
<field tfid="{5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}" key="__created by" type="text">
<content></content>
</field>
<field tfid="{234DC975-40DA-472B-B315-796C0FAA8D53}" key="meta title" type="Single-Line Text">
<content></content>
</field>
<field tfid="{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}" key="__updated" type="datetime">
<content></content>
</field>
<field tfid="{8CDC337E-A112-42FB-BBB4-4143751E123F}" key="__revision" type="text">
<content></content>
</field>
<field tfid="{9683EB7C-DE18-472D-B058-562573FAE23D}" key="titel" type="Single-Line Text">
<content></content>
</field>
<field tfid="{3E431DE1-525E-47A3-B6B0-1CCBEC3A8C98}" key="__workflow state" type="reference">
<content></content>
</field>
<field tfid="{001DD393-96C5-490B-924A-B0F25CD9EFD8}" key="__lock" type="memo">
<content></content>
</field>
<field tfid="{08D9129F-0967-4718-A158-2B8CC322D1E7}" key="tags" type="Treelist">
<content></content>
</field>
<field tfid="{93871141-7CB3-472E-9A75-6237A3BCC0F6}" key="tekstindhold" type="Rich Text">
<content></content>
</field>
<field tfid="{F1F0A054-010A-41F1-B0AC-D0D658727181}" key="teaser" type="Multi-Line Text">
<content></content>
</field>
</fields>
</item>
</item>
So my question is: How do i filter out an article if it is already shown in the list, so it doesn't show up more than one time, even though it has more than one tags in common with the lists tags.
And if some of you know how to sort my articles in the lists after date, that would also be great.
I hope that you understand my problem, and some of you would like to help me :)
Thanks
-Kim Andersen