Copied to clipboard

Flag this post as spam?

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


  • Jan Fosgerau 65 posts 89 karma points
    Dec 03, 2009 @ 11:20
    Jan Fosgerau
    0

    Page list - containing folder as headline. how to write this macro

    hey there.

    im new to xslt - as in i dont get it at all.

    and i need to have a macro that writes out my nodes very specifically.

    my structure is as such.

    Default Page
            Info Page (just info)
            Building Page (page that shows all the info below listed out nicely)
                    Area Code 1 (folder to contain the various buildings - just a headline on building page)
                           Buidling one (page with building info - Link to this page on building page)
                           Building two  (same)
                          
                           Building three (same)
                  Area Code 2 (etc.etc.)
                           Building four
                           Building Five

     

    so when you click on the website to the Building page - you see this list on the page.

     

    Area Code 1 (headline)

                Building One  (link)
                Building Two  (link)
                Building Three  (link)

    Area Code 2 (headline)

                Building Four (link)
                Building Five  (link)

     

     

    i have been trying to tinker with the various default macros and searched for sumthing like this - but have been unable to do so,

    i hope someone can give a good example of this how the macro would look like.

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Dec 03, 2009 @ 11:37
    Thomas Höhler
    0

    This shouldn't be such complicated: this will be some nested lists with startpoint at a defined level ($currentPage/@level). Take a look into the sitemap xslt template. If you have different documenttypes you can call own subtemplates to output what you want depending on the node where you are.

    If you need more help please tell me from which doctyoes the nodes are.

    Thomas

  • Jan Fosgerau 65 posts 89 karma points
    Dec 03, 2009 @ 12:36
    Jan Fosgerau
    0

    (Buildingpage)

    this page has struture set to allow the (headline) page to be place into it.
    also here the macro would be place in the template. that would list all (headline) / (link)

    (headline)

    i have a empty document type for the (headline).  was thinking that in the xslt ill just remove the <a href></a> so that it doesent go anywhere.

    only thing on the (headline) is that in structure i have allowed the (link) document type to be added to it.

    (link)

    The building document type has building info - and will also contain further links to that specific building. they are not to be shown on the (Buildingpage).

     

    atleast thats how i was thinking of doing it.

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 09:15
    Jan Fosgerau
    0

    ive been trying to look at that Sitemap macro.

     

    but i cant make heads or tails of it.

     

    i wanna limit that macro to my current page (and only that page) not showing anything else but the current page and its children.

    but how to write it im at a loss.    - trying to look at some turtorials hoping that ill get a greater understanding of it.

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Dec 04, 2009 @ 09:27
    Thomas Höhler
    0

    I will do an example for you this morning, have to do some prio work first (about 2 h)

    Thomas

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 09:47
    Jan Fosgerau
    0

    thank you! :D

    im continuing to look through some turtorials hopefully getting it before.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Dec 04, 2009 @ 10:02
    Thomas Höhler
    0

    prio work slipped to the afternoon due to other requirements that have to be defined.

    So the following xslt you can place into the Building Template and the Areas template

    <?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"
    exclude-result-prefixes="msxml umbraco.library">

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

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$currentPage/@level = 2">
    <!-- I am at level 2 of the hierachy => I am at the Building Page -->
    <xsl:call-template name="WriteAreas">
    <xsl:with-param name="actualNode" select="$currentPage"></xsl:with-param>
    </xsl:call-template>
    </xsl:when>
    <xsl:when test="$currentPage/@level = 3">
    <!-- I am at level 3 of the hierachy => I am at an Area Page -->
    <xsl:call-template name="WriteBuildings">
    <xsl:with-param name="actualArea" select="$currentPage"></xsl:with-param>
    </xsl:call-template>
    </xsl:when>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="WriteAreas">
    <xsl:param name="actualNode"></xsl:param>
    <ul>
    <xsl:for-each select="$actualNode/node">
    <li>
    <xsl:value-of select="@nodeName" />
    <!-- this writes the all AreaCodes -->
    <xsl:call-template name="WriteBuildings">
    <xsl:with-param name="actualArea"></xsl:with-param>
    </xsl:call-template>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

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

    </xsl:stylesheet>

    For learning xslt in umbraco take a look at Doug's blog: http://blog.percipientstudios.com/ especially the two blogentries http://blog.percipientstudios.com/2009/4/11/anatomy-of-an-umbraco-xslt-file.aspx and http://blog.percipientstudios.com/2009/5/5/your-first-umbraco-xslt-macro.aspx

    hth, Thomas

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 10:07
    Jan Fosgerau
    0

    this is what ive come up with so far.

    <xsl:template match="/">
    <ul>
        <xsl:for-each select="$currentPage/node">
        <li>
             <xsl:value-of select="@nodeName"/>
            </li>
            <ul>
            <xsl:for-each select="$currentPage/node/node">
                 <li>
                 <xsl:value-of select="current()/@nodeName"/><br />
                 </li>
            </xsl:for-each>
            </ul>
        </xsl:for-each>
    </ul> 
    </xsl:template>

    unfortunately it lists all buildings in each folder. instead of each individuells folders content.

    Folder 1
          building 1 right
          building 2 right
          building 3 right
          building 4 wrong
          building 5 wrong
    Folder 2
          building 1 wrong
          building 2 wrong
          building 3 wrong
          building 4 right
          building 5 right

    (which is of course because i dont know how to tell it to run through each folder and its child node and then onto the next. )

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 10:07
    Jan Fosgerau
    0

    oh diddent see you had posted sumthing! (no update)

    ill look at it right away!

    Thank you!

     

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 10:42
    Jan Fosgerau
    0

    unfortunately it diddent work. and only error im getting is that

    Error parsing XSLT file: \xslt\test2.xslt on my page

    think its because my explaination of how the structure is setup.
    Content
           Website
                    Building list <- macro                 (current page)

                          Area code 1(not visitable)   (level 2 ??? - writeareas)
                                 building 1(link)              (level 3 ??? - writebuildings)
                                 building 2(link)              (level 3 ??? - writebuildings)

                          Area code 2(not visitable)   (level 2 ??? - writeareas)
                                 building 3(link)              (level 3 ??? - write buildings)

    i hope im making sense - ill look at those blog links too.

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 11:07
    Jan Fosgerau
    0

    ive tried to take it apart bit by bit - and it only lists "anything" when i remove the Write buildings

    and then lists area codes - but when i add the bits with write buildings it cant parse it.

    not sure whats wrong :(



  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 11:09
    Jan Fosgerau
    0

                            <xsl:when test="$currentPage/@level = 3">
                                    <!-- I am at level 3 of the hierachy => I am at an Area Page -->
                                    <xsl:call-template name="WriteBuildings">
                                            <xsl:with-param name="actualArea" select="$currentPage"></xsl:with-param>
                                    </xsl:call-template>
                            </xsl:when>

    also dont think i need this if you click the building link - it will open that template and show the building info

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Dec 04, 2009 @ 11:36
    Thomas Höhler
    0

    Can I get access to the umbraco installation so that I have a look into it at the noon? If so mail me the credentials to "th |at| thoehler |dot| com"

    Thomas

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 11:52
    Jan Fosgerau
    0

    unfortunately i dont have it staged atm - its on my local machine only atm.

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 12:07
    Jan Fosgerau
    0

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="documentTypeAlias" select="string('PostNummer')"/>
    <xsl:variable name="documentTypeAlias2" select="string('BoligInfo')"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
        <xsl:for-each select="$currentPage/node/node [@nodeTypeAlias = $documentTypeAlias2 and string(data [@alias='umbracoNaviHide']) != '1']">
            <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                </a>
            </li>
        </xsl:for-each>
    </xsl:for-each>
    </ul>

    </xsl:template>

     

    cant this be altered somehow ? . so that it only shows each "postnummer (areacode) and its children boliginfo (buildings) and then shows the next Postnummer+children.

    i sorry if i cant describe it better,  

    newbieness is swarming me at the moment.

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 12:24
    Jan Fosgerau
    0

    dont know if this helps - but did screen shot of my folder structure on umbraco.

    http://i24.photobucket.com/albums/c48/redwind85/UmbracoLevel.jpg

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 14:15
    Jan Fosgerau
    0

    Ok i have a solution. after going through a turtorial about xpath disasembled the sitemap macro

    after alot of testing tinkering - and luck <---

    i found what i was looking for.


    <xsl:param name="currentPage"/>

    <!-- have to set this at 4 or it wont show anything -->
    <xsl:variable name="maxLevelForSitemap" select="4"/>

    <xsl:template match="/">
        <div id="sitemap">
            <xsl:call-template name="drawNodes"> 

                <!-- i change this to only include currentpage which seemed to do what i whant -->
                <xsl:with-param name="parent" select="$currentPage"/> 
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="drawNodes">
        <xsl:param name="parent"/>
            <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
                <ul>
                <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
                    <li> 
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName"/>
                    </a> 
                        <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">  
                            <xsl:call-template name="drawNodes">   
                                <xsl:with-param name="parent" select="."/>   
                            </xsl:call-template> 
                        </xsl:if>
                    </li>
                </xsl:for-each>
                </ul>
            </xsl:if>
    </xsl:template>

     

    i would like to remove the maxlevelforsitemap part of this - just to clean it up alittle. but this works perfectly.

     

    would there be anything bad about doing it this way ?.  or is there a way to simplify this more ?.  (removing the maxlevelforsitemap)

  • Jan Fosgerau 65 posts 89 karma points
    Dec 04, 2009 @ 14:37
    Jan Fosgerau
    0

    i needed to control my document types so i added these.

    <xsl:variable name="documentTypeAlias" select="string('PostNummer')"/>
    <xsl:variable name="documentTypeAlias2" select="string('BoligInfo')"/>

    then i added these IF to the For each sentence to elliminate the <a href></a> to the (postnummer) as they where showing as links

                <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
                    <li>
                    <xsl:if test="@nodeTypeAlias = $documentTypeAlias">
                        <xsl:value-of select="@nodeName"/>   
                    </xsl:if>
                    <xsl:if test="@nodeTypeAlias = $documentTypeAlias2">
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName"/>
                        </a>         
                    </xsl:if>
                        <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">  
                            <xsl:call-template name="drawNodes">   
                                <xsl:with-param name="parent" select="."/>   
                            </xsl:call-template> 
                        </xsl:if>

                    </li>
                </xsl:for-each>

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Dec 04, 2009 @ 22:38
    Chriztian Steinmeier
    0

    Hi Jan,

    Take a look at this way of doing it, starting from scratch - based on the image you posted above:

    <?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:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output
            method="xml"
            indent="yes"
            omit-xml-declaration="yes"
        />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <div id="map">
                <!-- Process nodes below the 'Ejendomme' node -->
                <xsl:apply-templates select="$currentPage//node[@nodeName = 'Ejendomme']/node" /> 
            </div>
        </xsl:template>
    
        <!-- Template for Area Code -->
        <xsl:template match="node[@nodeTypeAlias = 'PostNummer']">
            <h2>
                <xsl:apply-templates select="@nodeName" />
            </h2>
    
            <!-- If there's at least one node below this that's not hidden, create a list of buildings -->
            <xsl:if test="node[not(data[@alias = 'umbracoNaviHide'] = 1)]">
                <ul>
                    <xsl:apply-templates select="node" />
                </ul>         
            </xsl:if>
        </xsl:template>
    
        <!-- Template for a Building -->
        <xsl:template match="node[@nodeTypeAlias = 'BoligInfo']">
            <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:apply-templates select="@nodeName" />
                </a>
            </li>
        </xsl:template>
    
        <!-- Never output these -->
        <xsl:template match="node[data[@alias = 'umbracoNaviHide'] = 1]" />
    
    </xsl:stylesheet>

    Feel free to ask, if the inline comments aren't sufficient in explaining what goes on. 

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft