Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 08, 2010 @ 00:39
    Ferdy Hoefakker
    0

    Looping through xslt split array

    Okay, new problem :)

    For my website, I have used the tag control so I can assign tags to my news posts. All fine and dandy so far. Now, when displaying them, I want to make the tags clickable so the user can immediatly filter for other posts with said tag.

    So, I split my tag list and put it in a xslt variable:

    <xsl:variable name="tags" select="umbraco.library:Split(websiteNewsItemTags, ',')" />

    I pass this data to a new template part:

    <xsl:call-template name="postTagList"><xsl:with-param name="tagList" select="$tags"/>

    And then with a for each, I try to get each seperate item.

    <xsl:template name="postTagList">
      <xsl:param name="tagList" />
      <xsl:for-each select="$tagList/value">
        <xsl:value-of select="$tagList/value" />
      </xsl:for-each>
    </xsl:template>

    It technically works. In the post that has 2 tags, it displays 2 values. The thing is, they are the same value, while they should be 2 different values. I am probably missing something that needs to be placed behind the /value in the value-of statement, but I have tried a dozen different things by now and it's starting to drive me nuts.

    Any help would be appreciated.

    -Ferdy

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Aug 08, 2010 @ 01:15
    Ali Sheikh Taheri
    0

    try this

    <xsl:template name="postTagList">
      <xsl:param name="tagList" />
      <xsl:for-each select="$tagList/value">
        <xsl:value-of select="." />
      </xsl:for-each>
    </xsl:template>

    Ali

     

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 08, 2010 @ 01:49
    Ferdy Hoefakker
    0

    Thanks for the attempt, but that gives me nothing at all I'm afraid :(

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Aug 08, 2010 @ 01:54
    Ali Sheikh Taheri
    0

    how about this?

     

    <xsl:template name="postTagList">
      <xsl:param name="tagList" />
      <xsl:for-each select="$tagList/value">
        <xsl:variable name="tag" select="." />
        <xsl:value-of select="$tag" />
      </xsl:for-each>
    </xsl:template>

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 08, 2010 @ 01:55
    Ferdy Hoefakker
    0

    Nope, still nothing

  • Sascha Wolter 615 posts 1101 karma points
    Aug 08, 2010 @ 02:43
    Sascha Wolter
    0

    Hi Ferdy,

    try this out:

    <xsl:for-each select="$tagList/values/value">
      <xsl:value-of select="." />
    </xsl:for-each>

    To have a look what the content of $tags is you could use

    <textarea style="width:400px; height: 300px;">
      <xsl:copy-of select="$tags" />
    </textarea>

    Cheers,
    Sascha

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 08, 2010 @ 02:50
    Ferdy Hoefakker
    0

    Alright, it seems that in my attempts to get it working, I changed the split function. After changing that back, Ali Taheri's solutions do infact work, both actually. My bad. If someone could explain why you have to use the "." though, that would be awesome.

    Also, thanks for the help anyway Sascha :)

    -Ferdy

  • Sascha Wolter 615 posts 1101 karma points
    Aug 08, 2010 @ 03:00
    Sascha Wolter
    1

    Hi Ferdy,

    The '.' refers to the current item, it is the same as using current(). When you are looping through the items you are in your (Ali's) code actually looping through the values of the items, that's why you just have to get the value by using '.'.

    Sascha

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 08, 2010 @ 03:01
    Ferdy Hoefakker
    0

    Hmm, that's a bit odd since I had actually tried current() but that didn't seem to be working. Oh well, probably had something else wrong at that point then. Thanks anyway :)

Please Sign in or register to post replies

Write your reply to:

Draft