Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Mar 10, 2011 @ 14:03
    Niklas Hjelm
    0

    Getting the parent for a url

    Hi im using this xslt to pick som products and show their data. 

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#xA0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>

      <xsl:template match="/">
        <xsl:variable name="preNodes">
              <xsl:variable name="relatedContent" select="$currentPage/productPicker" />
              <xsl:variable name="nodeIds" select="umbraco.library:Split($relatedContent, ',')" />
          <xsl:for-each select="$nodeIds/value">
                <xsl:copy-of select="umbraco.library:GetXmlNodeById(.)"/>
              </xsl:for-each>
        </xsl:variable>
      
      <xsl:variable name="nodes" select="msxml:node-set($preNodes)/*[@isDoc]" />
      <xsl:if test="count($nodes) > 0">

      <ul class="productList">
        <xsl:for-each select="$nodes">
      <li class="two left marginTop10px">
      

       <href="{umbraco.library:NiceUrl(@id)}">
         <xsl:value-of select="$currentPage/preceding::node/@nodeName"/>
        </a>   
        
      </li>
                
    </xsl:for-each>
        </ul>
    </xsl:if>
      </xsl:template>

    </xsl:stylesheet>

    This works fine but in the url I need to get the parent url instead of the current. 

      <xsl:value-of select="$currentPage/preceding::node/@nodeName"/>

    I tried this but it didn't work. Any ideas how to get the parent for the selected page and not the selected one?



    Thanks / Niklas

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 10, 2011 @ 14:14
    Tom Fulton
    0

    This should work:

    <xsl:value-of select="$currentPage/parent::*/@nodeName"/>

    -Tom

  • Niklas Hjelm 104 posts 125 karma points
    Mar 10, 2011 @ 14:27
    Niklas Hjelm
    0

    Hi Tom

    This only gets me the current page parent, not the one I have selected using the picker. 

    Example:

    Page showing the macro: /parent/pageShowingMacro

    The macro fetches pages selected with a picker

    /productPageParent/productpage

    I want to get the productPageParent not the parent. 

    Regards / Niklas

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 10, 2011 @ 14:32
    Tom Fulton
    0

    Sorry, I'm a little confused.  Where exactly are you wanting to get the parent page? Is it inside the second for-each loop where you right out the link?  If so just replace $currentPage with "." to indicate the current node in the for-each loop

    <xsl:value-of select="./parent::*/@nodeName"/>

     

  • Niklas Hjelm 104 posts 125 karma points
    Mar 10, 2011 @ 14:59
    Niklas Hjelm
    0

    Exactly. When I put your code in the second for each I don't get anything at all. 

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 10, 2011 @ 15:04
    Tom Fulton
    1

    Ok, I see the issue, the nodes are generated from umbraco.library:GetXmlNodeById which doesnt include the parent XML

    But you can use the @parentID attribute to retrieve it:

    <xsl:for-each select="$nodes">
      <li class="two left marginTop10px">
      
       <xsl:variable name="parentNode" select="umbraco.library:GetXmlNodeById(@parentID)"/>
       <a href="{umbraco.library:NiceUrl(@id)}">
           <xsl:value-of select="$parentNode/@nodeName"/>
        </a>   
      </li>
    </xsl:for-each>

    That should do it!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 10, 2011 @ 17:25
    Chriztian Steinmeier
    0

    Hi,

    Minor correction - the reason they don't include the surrounding XML is because they're fetched with the <xsl:copy-of /> instruction - the GetXmlNodeById() function returns a pointer to the node within the complete XML, but the copy-of destroys that relationship.

    Good call on using @parentID attribute to retrieve them!

    /Chriztian

  • Niklas Hjelm 104 posts 125 karma points
    Mar 14, 2011 @ 11:33
    Niklas Hjelm
    0

    Works fine, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft