Copied to clipboard

Flag this post as spam?

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


  • David Park 32 posts 52 karma points
    Nov 04, 2010 @ 22:06
    David Park
    0

    List sub pages from homepage - hopefully quick fix.

    Hi Folks,

    I have a quick question to ask that I hope will be easy for you guru's out there.

    I currently have this xslt (successfully) pulling offers image, offers title and offers summary from pages directly below it.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
        <div class="specialoffer" style="padding-left:10px;">
          <div style="width:220px;float:left;width:220px;">
            <xsl:value-of select="offerImage" disable-output-escaping="yes"/>
          </div>
          <div class="specialofferbody" style="float:right;width:420px;">
            <h2 class="specialoffer"><xsl:value-of select="offerTitle" disable-output-escaping="yes"/></h2>
            <xsl:value-of select="offerSummary" disable-output-escaping="yes"/>
            <a href="contact-us.aspx" class="bluebutton">Offer Enquiry</a>
          </div>
        </div>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

     

    Can someone please show me how to pull the offers title and the offers summary to my homepage, and if you're feeling extra generous please explain roughly how you achieved this?

    Also, if I have left out any vital info please ask and ye shall receive.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 04, 2010 @ 22:08
    Jan Skovgaard
    0

    Hi David

    Would'nt you be able to use exactly the same code?

    If the pages you want to list on your homepage are children of it, then you should be able to use the above code to list them unless I'm missing something?

    /Jan

  • David Park 32 posts 52 karma points
    Nov 04, 2010 @ 22:21
    David Park
    0

    Hi Jan,

    thanks for the quick response. I'm afraid it doesn't work. The homepage is on the same level as the Offers page right now, and the offers themselves are children of the Offers page. This is because I have a holding page on the top level. I tried adding the macro to the holding page, whereby the Offers page is a child, but it goes screwy! (makes multiple scrolling divs with no content).

    Thanks for trying!

    David.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 04, 2010 @ 22:38
    Jan Skovgaard
    1

    Ok, so if I understand you correctly it's actually not content from subpages under your homepage node you want to have displayed. But content from other nodes at the same level as the homepage node?

    In that case you can use the GetXmlNodeById extension from the umbraco.library.

    <xsl:variable name="contentSrc" select="umbraco.library:GetXmlNodeById(yourid)" /> - you can find the id of a node by focusing a node and look at the bottom left corner.

    You can now use the $contentSrc variable in your for-each loop to get the content.

    If you don't want to hardcode the id you can add a content picker to your homepage documet type, in which you can choose the node where you want the subnodes from.

    Then the variable could look something like this <xsl:variable name="contentSrc" select="umbraco.library:GetXmlNodeById($currentPage/YourPropertyName)" />

    Hope this helps

    /Jan

  • David Park 32 posts 52 karma points
    Nov 04, 2010 @ 22:42
    David Park
    0

    Hi Jan, I spotted something.

    Currently, My two special offers are child pages of the Special Offers page. When I added the macro to the homepage template, it did not find the required offers. BUT, when I copied the child pages (the offers) to directly below the homepage, the exact same XSTL worked. This leads me to believe that the XSLT only works for child pages directly below the page the macro is used on.

    The following sitemap didn't work:-

    Home
    Special offers
    - Offer 1
    - Offer 2

     

    the following sitemap did work:-

    Home
    - offer 1
    - offer 2
    Special Offers
    - offer 1
    - offer 2

     

    This means I just need to figure out how to make an xslt file that can target child pages of another node or level. Does this make sense? I hope so!

  • David Park 32 posts 52 karma points
    Nov 04, 2010 @ 22:48
    David Park
    0

    Hi Jan,

     

    sorry I must have replied while you were typing your response. Thanks for your solution, I will try my best to implement it now.

     

    Many thanks,

    David.

  • David Park 32 posts 52 karma points
    Nov 04, 2010 @ 22:58
    David Park
    0

    Hi Jan,

    Below is my best attempt at implementing your solution. Suffice to say it does not work. Please point out where I am going wrong.


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:variable name="contentSrc" select="umbraco.library:GetXmlNodeById(1055)" />

    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:for-each select="$contentSrc">
        <div class="specialoffer" style="padding-left:10px;">
          <div style="width:220px;float:left;width:220px;">
            <xsl:value-of select="offerImage" disable-output-escaping="yes"/>
          </div>
          <div class="specialofferbody" style="float:right;width:420px;">
            <h2 class="specialoffer"><xsl:value-of select="offerTitle" disable-output-escaping="yes"/></h2>
            <xsl:value-of select="offerSummary" disable-output-escaping="yes"/>
            <a href="contact-us.aspx" class="bluebutton">Offer Enquiry</a>
          </div>
        </div>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 04, 2010 @ 23:05
    Jan Skovgaard
    0

    Hi David

    In the above example you are just writing $contentSrc in your select statement in the for-each...

    You need all the other exciting stuff as you also have in the previous sample you posted

     

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">

    So now you just need to replace $currentPage with $contentSrc since this is now your starting point. So it should look like this

    <xsl:for-each select="$contentSrc/* [@isDoc and string(umbracoNaviHide) != '1']">

    try giving it a go.

    A minor tip...

    to see what XML is returned in your variable you can make a textarea and do a copy-of. You can do it like this

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

    It makes it a lot easier to figure out, which elements to match etc.

    /Jan

     

     

  • David Park 32 posts 52 karma points
    Nov 04, 2010 @ 23:19
    David Park
    0

    Hi Jan,

     

    That was really simple in the end. Thanks for the help!!

     

    This info will be really useful in the long run.

     

    David.

Please Sign in or register to post replies

Write your reply to:

Draft