Copied to clipboard

Flag this post as spam?

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


  • suzyb 464 posts 877 karma points
    May 17, 2011 @ 22:09
    suzyb
    0

    Select child node with specific name

    OK I'm stumped.  I want to select a specific child node something like this

    <xsl:value-of select="$settingsNode/descendant-or-self::orangeBoxContent" />

    but make the selected node dynamic. This works

    <xsl:value-of select="$settingsNode/descendant-or-self::*[name() = 'orangeBoxContent']" />

    but if I try doing this

    <xsl:value-of select="$settingsNode/descendant-or-self::*[name() = $contentName]" />

    it doesn't even though $contentName is set to "orangeBoxContent".  I feel like I'm so close but just don't know what I'm missing to get it to work.

  • suzyb 464 posts 877 karma points
    May 17, 2011 @ 22:13
    suzyb
    0

    btw this is a snippet of the xml structure

    <Settings id="1116" parentID="-1" level="1" writerID="0" creatorID="0" nodeType="1064" template="0" sortOrder="3" createDate="2011-04-28T12:37:33" updateDate="2011-05-17T19:46:45" nodeName="Settings" urlName="settings" writerName="admin" creatorName="admin" path="-1,1116" isDoc="">
        <siteName>Search Consultancy</siteName>
        <orangeBoxContent><![CDATA[
    <p>Sign up for Mail</p>

    <p>Proin tincidunt semper orci, et posuere ligula placerat quis.
    Fusce rutrum metus sit amet urna.</p>
    ]]></orangeBoxContent>
      </Settings>
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    May 17, 2011 @ 22:16
    Chriztian Steinmeier
    0

    Hi suzyb,

    When you set the contentName variable/param, remember to use single quotes:

    <!-- Select the string 'orangeBoxContent' -->
    <xsl:variable name="contentName" select="'orangeBoxContent'" />

    <!-- Select the <orangeBoxContent> below the current context node -->
    <xsl:variable name="contentName" select="orangeBoxContent" />

    Was that it?

    Oh, and by the way - when it's a direct child, just use a slash to select it:

    <xsl:value-of select="$settingsNode/*[name() = $contentName]" /> 

    /Chriztian

  • suzyb 464 posts 877 karma points
    May 17, 2011 @ 23:34
    suzyb
    0

    Thanks Chriztian, adding the single quotes worked.

    Although I think I could have avoided the hassle if I just tried what I intended to do in the first place.  I was using that text string to check what I wanted to do was possible.  But I intended to get the value of contentName from a macro parameter.  When I actually did that, it worked fine.

  • 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