Copied to clipboard

Flag this post as spam?

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


  • ds 191 posts 223 karma points
    Aug 12, 2010 @ 12:05
    ds
    0

    How to check a field

    Hi everyone,

    I have such structure...

    - Flash

    - June 

    - Picture

    - Picture

    - July

    - Pictures

    - Video

     

    using an xslt file which turns infos into an xml file.

    <gallery title="Standalone example" description="Slideshow example demonstrating event listeners.">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <album lgPath="http://localhost" tnPath="http://localhost" title="{./data [@alias = 'albumTitle']}" description="{./data [@alias = 'albumDescription']}">
            <xsl:for-each select="node">
                    <img src="{./data [@alias = 'image']}" title="{./data [@alias = 'title']}" caption="{./data [@alias = 'caption']}" link="{./data [@alias = 'link']}" target="_blank" pause="" />
            </xsl:for-each>
        </album>
        <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example">
            <xsl:for-each select="node">
                <img src="{./data [@alias = 'video']}" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause=""/>
            </xsl:for-each>
        </album>
    </gallery>

    As you can see, there are two album nodes, one for images one for videos. What I try to do is to check video or image field. For example if in June there is not any video, then only display image album node.

    After searching on umbraco, I could not find a solution so far...

    <xsl:if test="string(./data [@alias='video']) != ''">
        <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example" tn="http://localhost/flash/gallery/album1/preview.jpg">
            <xsl:for-each select="node">
                    <img src="{./data [@alias = 'video']}" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause=""/>
            </xsl:for-each>
        </album>
    </xsl:if>

    I tried with xsl:if but did not work out.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 12, 2010 @ 12:47
    Chriztian Steinmeier
    0

    Hi ds,

    A great way to do this with XSLT is to define separate templates for the video and image types, and then just process each type individually - something like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <gallery title="Standalone example" description="Slideshow example demonstrating event listeners.">
    
                <xsl:if test="node[data[@alias = 'image']][not(data[@alias = 'umbracoNaviHide'] = 1)]">
                    <album lgPath="http://localhost" tnPath="http://localhost" title="{data[@alias = 'albumTitle']}" description="{data[@alias = 'albumDescription']}">
                        <!-- Process all images -->
                        <xsl:apply-templates select="node[data[@alias = 'image']]" />
                    </album>
                </xsl:if>
    
                <xsl:if test="node[data[@alias = 'video']][not(data[@alias = 'umbracoNaviHide'] = 1)]">
                    <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example">
                        <!-- Process all videos -->
                        <xsl:apply-templates select="node[data[@alias = 'video']]" />
                    </album>
                </xsl:if>
            </gallery>
        </xsl:template>
    
        <!-- Template for images -->
        <xsl:template match="node[data[@alias = 'image']]">
            <img src="{data[@alias = 'image']}" title="{data[@alias = 'title']}" caption="{data[@alias = 'caption']}" link="{data[@alias = 'link']}" target="_blank" pause="" />
        </xsl:template>
    
        <!-- Template for Videos -->
        <xsl:template match="node[data[@alias = 'video']]">
            <img src="{data[@alias = 'video']}" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause="" />
        </xsl:template>
    
        <!-- Empty template for hidden nodes -->
        <xsl:template match="node[data[@alias = 'umbracoNaviHide'] = 1]" />
    
    </xsl:stylesheet>
    

    /Chriztian 

  • ds 191 posts 223 karma points
    Aug 12, 2010 @ 15:20
    ds
    0

    Hi Chriztian,

    I made some changes on your code snippet,

           <gallery title="Standalone example" description="Slideshow example demonstrating event listeners.">
                <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
                    <xsl:if test="node[data[@alias = 'image']]">
                        <album lgPath="http://localhost" tnPath="http://localhost" title="{data[@alias = 'albumTitle']}" description="{data[@alias = 'albumDescription']}">
                            <!-- Process all images -->
                            <xsl:for-each select="node">
                                <xsl:apply-templates select="node[data[@alias = 'image']]" />
                            </xsl:for-each>
                        </album>
                    </xsl:if>
    
                    <xsl:if test="node[data[@alias = 'video']]">
                        <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example">
                            <!-- Process all videos -->
                            <xsl:for-each select="node">
                                <xsl:apply-templates select="node[data[@alias = 'video']]" />
                            </xsl:for-each>
                        </album>
                    </xsl:if>
                </xsl:for-each>
            </gallery>

     

    But based on following structure I placed a macro on "Flash" node.

    - Flash

    - June 

    - Picture

    - Picture

    - July

    - Pictures

    - Video

    I gave it a try from this link XPATH Axes and their Shortcuts but with this code snippet, I can only reach till June node. How can I go deeper and check child nodes of June or July.

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 13, 2010 @ 09:34
    Chriztian Steinmeier
    0

    Hi ds,

    You can use the descendant:: axis (//) for this, e.g.:

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

    - will select all nodes below $currentPage which has the 'image' property, regardless of level

    If you want to group by month you could add another for-each inside, e.g.:

    <xsl:for-each select="$currentPage/node">
      <!-- Output monthname -->
      <h2><xsl:value-of select="@nodeName" /></h2>
      <xsl:for-each select="node[data[@alias = 'image']]">
          <!-- do stuff -->
      </xsl:for-each>
    </xsl:for-each>

    /Chriztian

  • ds 191 posts 223 karma points
    Aug 13, 2010 @ 15:59
    ds
    0

    Hi Chriztian,

    Even though I tried with your code snippet, It does not give me the result.

    Let me ask you in another way.

    For such an outpout from xslt in the following, what should I do?

    <gallery title="Standalone example" description="Slideshow example demonstrating event listeners.">
      <album lgPath="http://localhost" tnPath="http://localhost" title="June 2010" description="">
          <img src="/media/892/asd.png" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause=""/>
          <img src="/media/890/1.f4v" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause=""/>
      </album>
    </gallery>

     

     

     

     

  • 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