Copied to clipboard

Flag this post as spam?

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


  • anthony hall 222 posts 536 karma points
    Sep 21, 2009 @ 17:48
    anthony hall
    1

    extract node value from array

    I'm using a checkboxlist  which contains the followings node values

    1110, 1111,  1112, 1113

    what would be the best way with xslt do extract a single node value

    ie i want to display all content that has a value of '1111'

     

     

     

     

  • anthony hall 222 posts 536 karma points
    Sep 21, 2009 @ 18:29
    anthony hall
    0

    hmm, maybe i haven't explain my question very well. So when you use a datatype that give you multiple option

    ie checkbox list or a list box. How do you work with these values in xslt. As you get an array

    1110, 1111,  1112, 1113

    so how would i do a foreach and just get '1110'

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 21, 2009 @ 18:49
    Lee Kelleher
    1

    Hi Anthony,

    You can use the Split method from the umbraco.library, like this:

    <xsl:variable name="nodeIds" select="umbraco.library:Split('1110,1111,1112,1113', ',')" />
    <xsl:for-each select="$nodeIds/value">
        <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)"/>
        <a href="{umbraco.library:NiceUrl($node/@id)}">
            <xsl:value-of select="$node/@nodeName" />
        </a>
    </xsl:for-each>

    Inside the for-each loop, you can extract whatever page data that you want.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 21, 2009 @ 18:54
    Sebastiaan Janssen
    1

    I did it like this:

        <xsl:variable name="categories" select="umbraco.library:Split($currentPage/data [@alias = 'categories'], ',')" />
        <xsl:for-each select="$categories/value">
          <xsl:if test=". = 1151">
            Do something
          </xsl:if>
        </xsl:for-each>
    

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 21, 2009 @ 18:55
    Sebastiaan Janssen
    1

    Ha, I was too slow in writing my code, and Lee's is even better ;-)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 21, 2009 @ 19:16
    Lee Kelleher
    0

    No worries Sebastiaan, it's the same concept - great minds think alike!

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Sep 21, 2009 @ 20:04
    Casey Neehouse
    3

    I may be misinterpreting this, but to get all nodes that contain 1110, then you would use contains....

    $nodesToFilter[contains(data[@alias='categories'],'1110')]

    note that you may want to concatenate commas around both parameters, as 1110 will match 1110, as well as 11110 and 11100-9, etc.  Not a problem on small sites, but, I have some sites with ids that high.

    $nodesToFilter[contains(concat(',',data[@alias='categories'],','),concat(',','1110',','))]

     

  • anthony hall 222 posts 536 karma points
    Sep 22, 2009 @ 08:34
    anthony hall
    0

    thanks really appreciate the response, actually learn alot thru these answers. I've gone with casey's 'contain' method. 

    here's what i've got. Any thoughts on how i could add the if statement to the foreach,  

     

    <xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle']">

    <xsl:if test="contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">

    // content here. 

    </xsl:if>

    </xsl:for-each>

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 23, 2009 @ 05:28
    Sebastiaan Janssen
    0

    This should work:

    <xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">

    ...

    </xsl:for-each>

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 23, 2009 @ 05:29
    Sebastiaan Janssen
    0

    Oops, missing a "]" at the end there, so:

    <xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))]">

    ...

    </xsl:for-each>

Please Sign in or register to post replies

Write your reply to:

Draft