Copied to clipboard

Flag this post as spam?

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


  • Daniel Bardi 927 posts 2562 karma points
    Dec 14, 2010 @ 23:16
    Daniel Bardi
    0

    How can I modify XSLTSearch to support searching media nodes

    Client needs media to be searched.  I know XSLT searches the content properties, but I need it to support searching the media properties.

    Media is accessed differently than content, but is there a bit of XSLT that I can add to the XSLT file to check if the starting node is a media item and search accordingly?

    I was hoping to do this using the existing XSLTSearch without much modification.

    The result should be a direct link to the media file (i.e. umbracoFile property)

    Thanks for any insight.

  • Sascha Wolter 615 posts 1101 karma points
    Dec 15, 2010 @ 01:52
    Sascha Wolter
    0

    Hi Daniel,

    You basically have to modify the possibleNodes variable. I've done this a couple of times now and it works a treat, however keep an eye on performance if that is an issue. It goes something like this:

    - create a custom variable with a 'root' element

    - add as many nodes to it as you need, using copy-of

    - generate a proper node set, replacing the existing possibleNodes variable

     

    <xsl:variable name="possibleNodesRaw">

        <container>

            <xsl:if test="is current node a media item?">

                <xsl:for-each select="$theMediaStartNode/.....">

                    <xsl:copy-of select="current()" />

                </xsl:for-each>

            </xsl:if>

            <xsl:if test="another condition">

                <!-- add as many nodes as you like -->

            </xsl:if>

        </container>

    </xsl:variable>

    <xsl:variable name="possibleNodes" select="msxml:node-set($possibleNodesRaw)/container/*[@isDoc]" />

    The search script will then use these nodes for all search operations.

    Hope that helps,

    Sascha

  • Ernst Utvik 123 posts 235 karma points
    Apr 08, 2011 @ 00:49
    Ernst Utvik
    0

    Hi.

    I have followed the instructions above but get no results when searching. The search searches the correct media nodes and the parameters should be correct, but still no results. Did a copy-of to see the raw data of my possibleNodes variable, and this returns the following for each media item: 

    <Image id="1056" version="b6b7dce1-9f23-412a-b2fc-5eaf7912cd1b" parentID="1055" level="4" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2011-04-05T13:43:40" updateDate="2011-04-05T13:43:41" nodeName="random image" urlName="randomimage" writerName="admin" nodeTypeAlias="Image" path="-1,1053,1054,1055,1056"><umbracoFile>/media/35/ernst.jpg</umbracoFile><imgDescription>Random bilde for testing av galleri</imgDescription><imgTags>Ernst,Eliah</imgTags><umbracoWidth>453</umbracoWidth><umbracoHeight>604</umbracoHeight><umbracoBytes>60518</umbracoBytes><umbracoExtension>jpg</umbracoExtension></Image>

    The properties im searching is @nodeName,imgTags,imgDescription. 

    Any idea what I am missing? Posting the only change I have made to the xslt:

        <xsl:variable name="possibleNodesRaw">
          <container>    
            <xsl:for-each select="umbraco.library:GetMedia(1053, '0')/descendant::* [@nodeTypeAlias='Image']">  
              <xsl:copy-of select="current()" />  
            </xsl:for-each>  
          </container>  
        </xsl:variable>
        <!-- reduce the number of nodes for applying all the functions in the next step -->
        <xsl:variable name="possibleNodes" select="msxml:node-set($possibleNodesRaw)/container/* " />

Please Sign in or register to post replies

Write your reply to:

Draft