Copied to clipboard

Flag this post as spam?

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


  • Mike 80 posts 101 karma points
    Oct 20, 2009 @ 09:01
    Mike
    0

    xlst get available crops?

    Hi,

    I am new to XSLT programming and I am figuring out how this works.

    I have a site created in Umbraco and implemented the ImageCropper data type. I have a page that shows subpages as thumbnails (from the default xslt starter templates) and would like to extend this.

    I would like to check if there are crops available and if so, use this, else use default thumbnail of the image.

    Also I would like to check on the crop item name ("Category Image Thumbnail" for example), because there could be more types later on.

    Here is a snippet from the umbraco.conifg file which shows two nodes. one with and one without crops. The furst one should show the umbracoFile, the second the crop

     

    <node id="1061" version="1fca41c1-c058-4415-a7a9-3ca3c912fffb" parentID="1060" level="3" writerID="0" creatorID="0" nodeType="1059" template="1058" sortOrder="1" createDate="2009-10-19T16:57:50" updateDate="2009-10-19T17:17:54" nodeName="Winches" urlName="winches" writerName="Administrator" creatorName="Administrator" nodeTypeAlias="Category" path="-1,1048,1060,1061">
            <data alias="umbracoFile">/media/389/winchlarge.jpg</data>
            <data alias="imageCropper"><![CDATA[]]></data>
            <data alias="umbracoUrlName" />
            <data alias="umbracoUrlAlias" />
            <data alias="umbracoRedirect" />
            <data alias="umbracoNaviHide">1</data>
            <data alias="MetaTitle" />
            <data alias="MetaDescription"><![CDATA[]]></data>
            <data alias="MetaKeywords"><![CDATA[]]></data>
            <data alias="Robots"><![CDATA[]]></data>
          </node>
          <node id="1064" version="b881efba-e907-4e5d-8941-e6830b1dc10c" parentID="1060" level="3" writerID="0" creatorID="0" nodeType="1059" template="1058" sortOrder="2" createDate="2009-10-19T17:21:53" updateDate="2009-10-19T17:25:18" nodeName="Cranes" urlName="cranes" writerName="Administrator" creatorName="Administrator" nodeTypeAlias="Category" path="-1,1048,1060,1064">
            <data alias="umbracoFile">/media/419/cranes222.jpg</data>
            <data alias="imageCropper">
              <crops date="19/10/2009 17:22:26">
                <crop name="Category Image Thumbnail" x="45" y="27" x2="594" y2="439" url="/media/419/cranes_Category Image Thumbnail.jpg" />

                <crop name="otherCrop" x="45" y="27" x2="594" y2="439" url="/media/419/cranes_otherCrop.jpg" />          </crops>
            </data>
            <data alias="umbracoUrlName" />
            <data alias="umbracoUrlAlias" />
            <data alias="umbracoRedirect" />
            <data alias="umbracoNaviHide">1</data>
            <data alias="MetaTitle" />
            <data alias="MetaDescription"><![CDATA[]]></data>
            <data alias="MetaKeywords"><![CDATA[]]></data>
            <data alias="Robots"><![CDATA[]]></data>
          </node>

    the template, i think, should be something like this, but i do not know how to check if there are crops available.  Hope somebody can help me out...

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul class="categories">

    <xsl:for-each select="$currentPage/node">
        <xsl:choose>
          <xsl:when test="<!-- crop with name is available -->">

              <li><a class="fthumb" href="{umbraco.library:NiceUrl(@id)}"  title="winches"><img width="140" height="105" alt="winches" src="{concat(substring-before(data [@alias='umbracoFile'],'.'), '_Category Image Thumbnail.jpg')}" /></a></li>

          </xsl:when>
          <xsl:otherwise>
             <li><a class="fthumb" href="{umbraco.library:NiceUrl(@id)}" title="winches"><im g width="140" height="105" alt="winches" src="{data [@alias='umbracoFile']}" /></a></li>
          </xsl:otherwise>
        </xsl:choose>


    </xsl:for-each>
    </ul>
    </xsl:template>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 20, 2009 @ 10:04
    Dirk De Grave
    0

    Hi,

    Your test should be

    <xsl:when test="./data [@alias = 'imageCropper']/crops/crop [@name = 'YOURCROPNAME']">

     

    Hope this helps.

     

    Regards,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft