Copied to clipboard

Flag this post as spam?

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


  • Tim Officer 18 posts 39 karma points
    Nov 04, 2011 @ 20:39
    Tim Officer
    0

    trying to get node properties from node ID

    I have a placeholder page in Umbraco that renders Biographies. The placeholder page gets a node id from a query string and then renders the data for each bio. The issue is that I have a breadcrumb navigation, so on the placeholder page it looks like this: (biography is the placeholder page)

    Our Team : Partners : Biography

    What I want it to look like is this:

    Our Team : Partners : person's name

     

    so, in my XSLT I getting a nodeId from a query string using:

      <xsl:variable name="bioNodeId" select="umbraco.library:RequestQueryString('Id')"/>

    with that I am trying to get the node using:

      <xsl:variable name="bioNode" select="umbraco.library:GetXmlNodeById($bioNodeId)/node"/>

    once I have the node I should be able to access the EmployeeFirstName property on it.

    here is my select, which isn't returning anything...
    <xsl:value-of select="$bioNode/data[@alias='EmployeeFirstName']"/>

    so my question is how to i access the properties of node that I am trying to get using my querystring?

    I should be able to get the XML for the node using GetXMLNodeById, but how do I find the EmployeeFirstName property within that?

     

    Hope this all makes sense, thanks for the help :)               

     

    here is the full XSLT:

     

      <xsl:variable name="minLevel" select="0"/>
      <!-- get the query string with the biography node id -->
      <xsl:variable name="bioNodeId" select="umbraco.library:RequestQueryString('Id')"/>
      <xsl:variable name="bioNode" select="umbraco.library:GetXmlNodeById($bioNodeId)/node"/>
      <!-- Input the documenttype you want here -->
     
     
      <xsl:template match="/">
        <xsl:if test="$currentPage/@level &gt; $minLevel">
          <ul class="breadCrumbNav">
            <li>
              <a href="/">Home</a>
            </li>
            <xsl:for-each select="$currentPage/ancestor::* [@level &gt; $minLevel and @nodeName != 'Home']">
              <li> :
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName"/>
                </a>
              </li>
            </xsl:for-each>
            <!-- print currentpage -->
              <li> :
                <a href="" class="currentBread">
                  <!-- when on a biography page show the employee's name -->
                  <!-- string($currentPage/data [@alias='PageHeader']) -->
                    <xsl:choose>
                      <xsl:when test="$currentPage/@nodeName = 'Biography'">
                     
                          <xsl:value-of select="$bioNode/data[@alias='EmployeeFirstName']"/>
                     
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="$currentPage/@nodeName"/>
                      </xsl:otherwise>
                    </xsl:choose>
                </a>
              </li>
          </ul>
        </xsl:if>
      </xsl:template>

     

  • Tim Officer 18 posts 39 karma points
    Nov 04, 2011 @ 21:02
    Tim Officer
    0

    I am able to get the nodeName using @nodeName:

    <xsl:value-of select="$bioNode/@nodeName"/>

     

    any idea why I can't get the properties?

    My property name is EmployeeFirstName so I am doing

    <xsl:value-of select="$bioNode/data[@alias='EmployeeFirstName']"/>

    I thought this should work, but it's not.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Nov 05, 2011 @ 16:38
    Jan Skovgaard
    0

    Hi Tim

    What does the returned XML from the $bioNode variable look like?

    Could you try and write it out like this and tell us what XML you get returned?

    <textarea>
    <xsl:copy-of select="$bioNode" />
    </textarea>

    /Jan

  • Andrei Canef 33 posts 84 karma points
    Nov 05, 2011 @ 21:30
    Andrei Canef
    0

    Hi Tim, 

     

    If you are using the old schema, your syntax is correct. 
    However, if you're using the current schema, <xsl:value-of select="$bioNode/EmployeeFirstName"/> should return the correct value.

     

    Andrei 

  • Tim Officer 18 posts 39 karma points
    Nov 07, 2011 @ 15:29
    Tim Officer
    0

    @Jan this is what is returned using <textarea>

    <Biography id="1141" parentID="1128" level="3" writerID="0" creatorID="0" nodeType="1053" template="0" sortOrder="1" createDate="2011-10-27T12:08:50" updateDate="2011-11-04T12:11:52" nodeName="Akhrass, Jameel" urlName="akhrass,-jameel" writerName="admin" creatorName="admin" path="-1,1060,1128,1141" isDoc=""><employeeFirstName>Jameel</employeeFirstName><employeeLastName>Akhrass</employeeLastName><title /><bioContent></bioContent><bioImageId /><bioAlternateImageId /></Biography>

    so I was doing that part right.

    Andrei, I was able to get the First and Last names using the new schema like you mentioned.

    I did notice that the new schema didn't like using property name with a capital letter first. EmployeeFirstName didn't return anything.

    employeeFirstName returned what I wanted....strange.

    but thank you guys very much for your help, I appreciate it.

  • Andrei Canef 33 posts 84 karma points
    Nov 07, 2011 @ 17:47
    Andrei Canef
    0

    Hi Tim, 

     

    It depends what the alias of your property is. I am pretty sure that by default, Umbraco will put your first letter in lowercase. As the alias is case-sensitive, it would explain why it didn't return the correct information if you were trying to access EmployeeFirstname. My apologies, I simply pasted the code you'd provided without realising the issue. 

     

    I'm glad it helped, though. 

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Nov 07, 2011 @ 17:54
    Jan Skovgaard
    0

    Hi Tim

    Just want to add to Andrei is posting above.

    The alias elements in the XML first letter are always lowecased and the document type elements first letters are always uppercased.

    But it's always a good idea to write out the XML to see what you're up against :)

    /Jan

  • Tim Officer 18 posts 39 karma points
    Nov 07, 2011 @ 20:24
    Tim Officer
    0

    Andrei, no worries, I was able to figure it out pretty quickly once I got the correct syntax from you.

    Jan, your trick out spitting out all the XML is a useful one and I will definetly use it again.

    thanks again for all your help guys, this place is great!

Please Sign in or register to post replies

Write your reply to:

Draft