Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jun 17, 2010 @ 14:29
    Sebastiaan Janssen
    0

    Count the nodes that have a valid ID somewhere in a property?

    Currently I have this pieces of XSLT:

            <xsl:for-each select="$hotSpotNodes">
              <xsl:variable name="hotSpotTargetSplitter" select="umbraco.library:Split(data [@alias ='hotSpotTarget'], '|')" />
    
              <xsl:variable name="hotSpot" select="umbraco.library:GetXmlNodeById($hotSpotTargetSplitter/value[2])" />
              <xsl:if test="$hotSpot/@id != ''">
              <!-- Do something -->
            </xsl:for-each>

    Is there any way in XSLT that I can count the number of nodes that have a valid ID after the first "|" symbol (as expressed in the above two variables)?

  • Josh Townson 67 posts 162 karma points
    Jun 17, 2010 @ 14:47
    Josh Townson
    0

    Doesn't seem like the best idea, but a simple one: - put the results into a nodeset and then count, and do whatever. But its 2 for-each loops where one did it in the past.

    <xsl:variable name="validIDs">
    <xsl:for-each select="$hotSpotNodes">
    <xsl:variable name="hotSpotTargetSplitter" select="umbraco.library:Split(data [@alias ='hotSpotTarget'], '|')" />
    <xsl:variable name="hotSpot" select="umbraco.library:GetXmlNodeById($hotSpotTargetSplitter/value[2])" />
    <xsl:if test="$hotSpot/@id != ''">
    <xsl:copy-of select="$hotSpot"/>
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="validIDNodes" select="msxml:node-set($validIDs)"/>
    <xsl:value-of select="count($validIDNodes/node)"/>

    Not tested, but it looks like it might work to me.

  • Shannon Deminick 1510 posts 5195 karma points hq
    Jun 17, 2010 @ 15:36
    Shannon Deminick
    0

    You can also use the EXSLT extensions to create node sets (msxml requires full trust i think)

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jun 17, 2010 @ 16:21
    Sebastiaan Janssen
    0

    Just what I needed Josh, thanks so much!

    Shannon: I know, but I was trying to avoid writing an extension, no problem with trust issues here. :-) Thanks!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies