Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    Oct 12, 2012 @ 22:20
    umbracocool
    0

    Search word in a text string

     

    Hello friends, I have been breaking my head with this. What I need is to find a word in a text string. For example:

    searching for "people" in "hello people, good morning."

    In php this is easy:

     <? php
         strstr($string, $word);
    ?>

     But in Xslt Umbraco I have not found anything. Help please!

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 12, 2012 @ 22:59
    Chriztian Steinmeier
    0

    Hi umbracocool,

    You use the contains() function for that, e.g.:

    <!-- Grab the site root -->
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <!-- Find nodes containing a specific string in the nodeName attribute -->
    <xsl:variable name="foundNodes" select="$siteRoot//*[@isDoc][contains(@nodeName, 'people')]" />
    
    <xsl:template match="/">
        <xsl:apply-templates select="$foundNodes" />
    </xsl:template>
    
    <xsl:template match="*[@isDoc]">
        <p>
            <xsl:value-of select="@nodeName" />
        </p>
    </xsl:template>
    

    /Chriztian

  • umbracocool 108 posts 197 karma points
    Oct 13, 2012 @ 03:25
    umbracocool
    0

    Hey brother, you saved my life, thank you very much, you're a genius, was crazy looking for this and could not find it. God bless you, Bye!

  • umbracocool 108 posts 197 karma points
    Oct 13, 2012 @ 03:36
    umbracocool
    0

    sorry brother, but a problem has arisen, and is not case sensitive. I mean if I look, pro example:

     "john" to "JOHN is a Man".

     It works for me! What do I do?

  • umbracocool 108 posts 197 karma points
    Oct 13, 2012 @ 03:55
    umbracocool
    0

    Ok brother, hehe using lowercase.Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft