Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Feb 18, 2010 @ 11:24
    Claushingebjerg
    0

    Check if self or ancestor is defined then use...

    I have some xslt which shows a series of images on the page.
    I would like it to check if the images are defined on the current page.
    If not it should check the parent page to see if they are defined there.
    If they are, then use them, if not then go back another level...

    My xslt so far:

    <xsl:if test="$currentPage/ancestor-or-self::node/data[@alias='toppic'] != ''">
       <xsl:variable name="documentNodeSet" select="$currentPage/ancestor-or-self::node/data[@alias='toppic']"/>
       <xsl:for-each select="$documentNodeSet/descendant::node">
           <img src="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}" />
       </xsl:for-each>
    </xsl:if>

    It works to some degree, but it takes all images, both those defined on the current page, and those on the parent page. Thats not really what i want. If toppic is defined on the current page, it shouldnt look to the parent...

    Any help appriciated :)

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 18, 2010 @ 11:48
    Jan Skovgaard
    0

    Dont you just need to write something like

    <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias='toppic']">

    <img src="yourmediacodeinhere" />

    </xsl:for-each>

    Won't that do?

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 18, 2010 @ 11:54
    Kim Andersen
    0

    Otherwise this might do the trick:

    <xsl:variable name="last">
        <data>
            <xsl:for-each select="$currentPage/ancestor-or-self::node[data[@alias='toppic'] != '' ">
                  <li>
                      <xsl:value-of select="@id"/>
                  </li>
            </xsl:for-each>
        </data>
    </xsl:variable>

    <xsl:variable name="nedarvId" select="umbraco.library:GetXmlNodeById(msxml:node-set($last)/data/li[last()])"/>

     

    I used this before to use some content from the parent node if it wasn't present on the current node. It's not the most beautiful XSLT I have written, but it worked in my case :)

    /Kim A

  • Claushingebjerg 939 posts 2574 karma points
    Feb 18, 2010 @ 12:14
    Claushingebjerg
    0

    I ended up with this

    <xsl:choose>
        <xsl:when test="string($currentPage/data [@alias='toppic']) != ''">
            <xsl:variable name="documentNodeSet" select="$currentPage/data[@alias='toppic']"/>
            <xsl:for-each select="$documentNodeSet/descendant::node">
                     <img alt="{umbraco.library:GetMedia(current(), 'false')/data [@alias='imgTitle']}"    src="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}" />
                     </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
                <xsl:variable name="documentNodeSet" select="$currentPage/ancestor::node/data[@alias='toppic']"/>
            <xsl:for-each select="$documentNodeSet/descendant::node">
                      <img alt="{umbraco.library:GetMedia(current(), 'false')/data [@alias='imgTitle']}"    src="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}" />
                     </xsl:for-each>
        </xsl:otherwise>
    </xsl:choose>

Please Sign in or register to post replies

Write your reply to:

Draft