Copied to clipboard

Flag this post as spam?

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


  • Adrian Inman 35 posts 59 karma points
    Aug 02, 2011 @ 17:51
    Adrian Inman
    1

    Death by XSLT - List nodes from another list

    I am trying to get a count of the number of nodes who's media field (id) pointed to media are of a certain type. Basically, I have a number of adverts which can either have flash, or images assocated with them. I need to know how many flash adverts there are.

    <xsl:variable name="source" select="umbraco.library:GetXmlNodeById(???)/*"/>
    <
    xsl:variable name="mediaItems" select="$source/promoMedia" />

      <xsl:for-each select="$mediaItems">
      <xsl:copy-of select="." />
      </xsl:for-each>

    outputs 

    <promoMedia>1083</promoMedia>
    <promoMedia>1173</promoMedia>
    <promoMedia>1174</promoMedia>
    <promoMedia>1175</promoMedia>

    Basically I am trying to pipe the output into umbraco.library:GetMedia so I can then get the media associated and check its local-name to see if it is "Flash" or "Image"

    Ideally, I want this in one line, but have no idea how to do it.

    I tried to do a loop and was going to increment a count, but can't do that either.

    Please help!

  • Lachlann 344 posts 626 karma points
    Aug 02, 2011 @ 18:11
    Lachlann
    0

    Hi Adrian

    I think i understand what you are aiming for

    <xsl:value-of select="count($mediaItems[umbraco.library:GetMedia(.)/umbracoType = 'flash'])"/>

     

    Does the above work?

     

    L

     

  • Adrian Inman 35 posts 59 karma points
    Aug 02, 2011 @ 18:14
    Adrian Inman
    0

    I don't see how as to get on one line, I'd need to put a list of items into the GetMedia call, but it ends up only operating on the first one.

  • Lachlann 344 posts 626 karma points
    Aug 02, 2011 @ 18:24
    Lachlann
    0

    Hmm thats strange so if your code is:

     

    <xsl:variable name="source" select="umbraco.library:GetXmlNodeById(???)/*"/>
    <
    xsl:variable name="mediaItems" select="$source/promoMedia" />

    <xsl:value-ofselect="count($mediaItems[umbraco.library:GetMedia(.)/umbracoExtension= 'flash'])"/>

     

    that doesnt output the number you would expect?
    could you output an xsl:copy-of the contents of $mediaItems[umbraco.library:GetMedia(.)/umbracoExtension= 'flash'] ?

    L

     

    ps i used umbracoType when it should have been umbracoExtension


  • Adrian Inman 35 posts 59 karma points
    Aug 02, 2011 @ 18:33
    Adrian Inman
    0

    After a bit of adjusting so it doesn't error

    <xsl:value-of select="count($mediaItems[umbraco.library:GetMedia(.,0)/umbracoExtension='Flash'])"/>

    Gives 0 when it should give 1

  • Lachlann 344 posts 626 karma points
    Aug 02, 2011 @ 18:41
    Lachlann
    0

    hmm so what does:

    <xsl:copy-of select="$mediaItems[umbraco.library:GetMedia(.,0)/umbracoExtension!='']"/>


    output?

    L

  • Adrian Inman 35 posts 59 karma points
    Aug 02, 2011 @ 18:44
    Adrian Inman
    0

    <promoMedia>1083</promoMedia>
    <promoMedia>1173</promoMedia>
    <promoMedia>1174</promoMedia>
    <promoMedia>1175</promoMedia>

    Which is excluding the one node I want to count. I think you're missing how I've defined the Flash media type in Umbraco, unless you need it to be different to how it is now - it doesn't have an extension property (I think)

  • Lachlann 344 posts 626 karma points
    Aug 03, 2011 @ 10:14
    Lachlann
    0

    Hi Adrian,

    Okay well thats a start at least :)

    How are the flash media types defined? i.e. what is the property on the media node?

    it seems that the one node you want to count doesnt have an umbracoExtension property but if we replace that for the property you are expecting we should be in business?

    L

Please Sign in or register to post replies

Write your reply to:

Draft