Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Jul 22, 2013 @ 12:55
    Kate
    0

    Diffrent doctypes on same page

    Hi

    I have a website which consists of only one page - a very long page.
    I would like it to be divided into sections and each section will have its own document type.
    All the different document types must then be assembled in one page in the order they appear in the menu tree.
    Document types can be used several times and not in any particular order.
    My menu tree looks like this:



    Do you have any idea how I do this - and does it make any sense what I have written :-)


  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jul 22, 2013 @ 13:00
    Hendy Racher
    0

    Hi Kate,

    Yes that structure looks to make sense - the top level page can get its data by looping though all child nodes.

     

  • Kate 267 posts 610 karma points
    Jul 22, 2013 @ 13:08
    Kate
    0

    Im am not very good at xslt, so I was hoping that you could help me a little on the way ;-)

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 22, 2013 @ 13:11
    Chriztian Steinmeier
    0

    Hi Kate,

    That makes perfect sense - we've done this several times. Depending on how you want to "navigate" the site here's a couple of tips on how we've been doing that:

    * Instead of using <a href="{umbraco.library:NiceURL(@id)}">, we're using <a href="#{@urlName}"> in the navigation macro (we use XSLT - you can do the same with Razor - key is to use the urlName property, since it should be safe for URLs)

    * Using that one to generate the IDs too, of course, e.g.: <div id="#{@urlName}"> for each child node - this way they'll always match - even on multi-language sites.

    /Chriztian

  • Kate 267 posts 610 karma points
    Jul 22, 2013 @ 13:16
    Kate
    0

    Hi Christian

    Thanks for your help, but my big problem is that I dont know how to loop though all the child nodes :-)

    /Kate

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 22, 2013 @ 13:16
    Chriztian Steinmeier
    100

    Hi Kate,

    Here's a simple macro to get you started - feel free to add more questions :-)

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <!-- Grab all the sections to show -->
        <xsl:variable name="sections" select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />
    
        <xsl:template match="/">
            <nav>
                <ul>
                    <xsl:apply-templates select="$sections" mode="nav" />
                </ul>
            </nav>
    
            <xsl:apply-templates select="$sections" mode="output" />
        </xsl:template>
    
        <!-- Navigation template -->
        <xsl:template match="*[@isDoc]" mode="nav">
            <li>
                <a href="#{@urlName}">
                    <xsl:value-of select="@nodeName" />
                </a>
            </li>
        </xsl:template>
    
        <!-- Output for each of the sections -->
        <xsl:template match="*[@isDoc]" mode="output">
            <section id="#{@urlName}">
                <header>
                    <h1><xsl:value-of select="@nodeName" /></h1>
                </header>
                <div class="text">
                    <xsl:value-of select="bodyText" disable-output-escaping="yes" />
                </div>
            </section>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • Kate 267 posts 610 karma points
    Jul 22, 2013 @ 13:18
    Kate
    0

    you are fast :-)
    What do I do if my sections have different content?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 22, 2013 @ 13:19
    Chriztian Steinmeier
    0

    PS: You may need to tweak the $siteRoot variable so it captures the "AllPages" node - I'm assuming that one is at level=1 (usually the case).

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 22, 2013 @ 13:23
    Chriztian Steinmeier
    1

    Hi again,

    That's the beautiful part - you can add templates for each kind of doctype if you need, e.g.:

       <!-- Output for each of the sections -->
        <xsl:template match="*[@isDoc]" mode="output" priority="-1">
            <section id="#{@urlName}">
                <header>
                    <h1><xsl:value-of select="@nodeName" /></h1>
                </header>
                <div class="text">
                    <xsl:value-of select="bodyText" disable-output-escaping="yes" />
                </div>
            </section>
        </xsl:template>
    
        <xsl:template match="NewsDoctypeAlias" mode="output">
            <!-- Output for News -->
        </xsl:template>
    
        <xsl:template match="StandardContentAlias" mode="output">
            <!-- Output for standard content -->
        </xsl:template>
    
    (Note that you need to add a priority attribute to the template I posted before in order to make the other templates "trump" the general one, if needed)

    /Chriztian

  • Kate 267 posts 610 karma points
    Jul 22, 2013 @ 13:25
    Kate
    0

    You are right, it is only in one level.

    I will have a go at it tomorrow and  then I'll probably come back with more questions :-)

    Thanks for your help :-)

  • Kate 267 posts 610 karma points
    Jul 22, 2013 @ 13:48
    Kate
    1

    it works like a charm :-)

    Again, Thanks for your help

    /Kate

  • Kate 267 posts 610 karma points
    Aug 04, 2013 @ 20:55
    Kate
    0

    Hi Chriztian

    Hope it's okay if I ask you a second question in this thread.
    I have 4 document types to be inserted  and then I thought if I could make xslt files for each template and then just make a reference to them.

    /Kate

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 05, 2013 @ 23:18
    Chriztian Steinmeier
    0

    Hi Kate,

    You can indeed - you can use either <xsl:import> or <xsl:include> for that - I wrote an article about them to explain the difference between them.

    /Chriztian

  • Kate 267 posts 610 karma points
    Aug 06, 2013 @ 09:08
    Kate
    0

    Thanks Chriztian

    I will try it out :-)

  • Kate 267 posts 610 karma points
    Aug 06, 2013 @ 09:41
    Kate
    0

    I have made this simple exampel with 2 xslt files (import.xslt and tester.xslt)

    import.xslt

    <?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="/">

    <!-- start writing XSLT -->
    <xsl:include href="tester.xslt" />

    </xsl:template>

    </xsl:stylesheet>

     

    tester.xslt

    <?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="/">
    <!-- start writing XSLT -->
    Dette indhold kommer fra en selvstændig xslt fil
    </xsl:template>

    </xsl:stylesheet>

     

    But I get an error when I try to save import.xslt

    Error occured
    System.Xml.Xsl.XslLoadException: 'xsl:include' cannot be a child of the 'xsl:template' element. An error occurred at d:\web\localuser\poly-control.dk\polycontrol2013\xslt\635113787350420012_temp.xslt(18,4).
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    Can you help me with that? :-)

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 06, 2013 @ 10:57
    Dennis Aaen
    0

    Hi Kate,

    One thing I notice is that your include of the tester.xslt file is included in the match. I believe that when you use an include, it must be include as I show here.

    <?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:includehref="tester.xslt"/>

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


    <xsl:paramname="currentPage"/>

    <xsl:templatematch="/">

    <!-- start writing XSLT -->


    </xsl:template>

    </xsl:stylesheet>

    But I don´t know if it´s the only thing that is wrong, because I don´t use the include tag very often in my XSLT files. But if I remember correctly it has to be included up there.

    Hope this can help you closer to get it Work.

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 06, 2013 @ 11:18
    Kate
    0

    Hi Dennis

    it almost works. I dont get the error anymore, but it does not showe my content in the tester.xslt file.

    My import file looks like that:

    <?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:include href="tester.xslt" />
    <xsl:template match="/">

    <!-- start writing XSLT -->
    yyyyy

    </xsl:template>

    </xsl:stylesheet>


  • Kate 267 posts 610 karma points
    Aug 06, 2013 @ 11:22
    Kate
    0

    I forgot this line :-(    Stupid me ;-)

    <xsl:apply-imports />
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 06, 2013 @ 11:23
    Dennis Aaen
    0

    Okay Kate, so you get it working now or?

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 06, 2013 @ 11:43
    Kate
    0

    Almost

    I can get it to work with <xsl:import href="tester.xslt" />.

    But what if I want to import two xslt files (test.xslt and test2.xslt). How du I do that?

    <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:import href="tester.xslt" />
    <xsl:import href="tester2.xslt" />
    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
    yyyyy
    <xsl:apply-imports />
    </xsl:template>


    </xsl:stylesheet>

     

  • Kate 267 posts 610 karma points
    Aug 07, 2013 @ 10:51
    Kate
    0

    I have made another exampel, maybe it will make et more understandable what Im trying to do :-)

    I would like each <xsl:template match="" mode="output"> conten in this file to be importet from another xslt fil. But I cant get it to work.

    I have placed the <xsl:import href="Multiside1.xslt" /> at the top
    and <xsl:apply-imports /> in the <xsl:template match="Multiside1" mode="output">

    First problem is that it does not print out the text I wrote in the Multiside1.xslt. It print out some  text I have on the page.

    Second problem is that I would like to have 3 diffrent xslt filses (Multiside1.xslt, Multiside2.xslt, Multiside3.xslt) but I dont know how to import them
    separately

    My Multiside1.xslt looks like this:

    <?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:template match="/">

    <!-- start writing XSLT -->
    Here is a bit of text from Multiside1.xslt

    </xsl:template>

    </xsl:stylesheet>

     

    This is the file I import the other files

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:umb="urn:umbraco.library"
    exclude-result-prefixes="umb"
    >
    <xsl:import href="Multiside1.xslt" />
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

    <xsl:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 2]" />

    <!-- Grab all the sections to show -->
    <xsl:variable name="sections" select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />

    <xsl:template match="/">
    <nav>
    <ul>
    <xsl:apply-templates select="$sections" mode="nav" />
    </ul>
    </nav>
    <xsl:apply-templates select="$sections" mode="output" />
    </xsl:template>

    <!-- Navigation template -->
    <xsl:template match="*[@isDoc]" mode="nav">
    <li>
    <a href="#{@urlName}">
    <xsl:value-of select="@nodeName" />
    </a>
    </li>
    </xsl:template>

    <!--I would like this templates content to come from another xslt file named = Multiside1-->
    <xsl:template match="Multiside1" mode="output">
    <!-- Output for News --> Indhold til side 1
    <section id="#{@urlName}">
    <header>
    <h1><xsl:value-of select="@nodeName" /></h1>
    </header>
    <div style="color:red;"><xsl:apply-imports /></div>
    </section>
    </xsl:template>

    <!--I would like this templates content to come from another xslt file named = Multiside2-->
    <xsl:template match="Multiside2" mode="output">
    <!-- Output for standard content --> Indhold til side 2
    <section id="#{@urlName}">
    <header>
    <h1><xsl:value-of select="@nodeName" /></h1>
    </header>
    </section>
    </xsl:template>

    <!--I would like this templates content to come from another xslt file named = Multiside3-->
    <xsl:template match="Multiside3" mode="output">
    <!-- Output for standard content --> Indhold til side 3
    <section id="#{@urlName}">
    <header>
    <h1><xsl:value-of select="@nodeName" /></h1>
    </header>
    </section>
    </xsl:template>

    </xsl:stylesheet>

    Hope anybody can help :-)

    /Kate

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 07, 2013 @ 11:29
    Chriztian Steinmeier
    0

    Hi Kate,

    See this simplified version (I've left out all the namesace declarations etc. for easier scanning) :

    Main.xslt

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <xsl:apply-templates select="$currentPage/*[@isDoc]" mode="nav" />
            <xsl:apply-templates select="$currentPage/*[@isDoc]" mode="output" />
        </xsl:template>
    
        <xsl:include href="NavTemplates.xslt" />
    
        <xsl:include href="OutputTemplates.xslt" />
    
    </xsl:stylesheet>
    

    NavTemplates.xslt

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
    
        <xsl:template match="*[@isDoc]" mode="nav">
            <!-- Do something -->
        </xsl:template>
    
    </xsl:stylesheet>
    

    OutputTemplates.xslt

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
    
        <xsl:template match="Document" mode="output">
            <!-- Do something -->
        </xsl:template>
    
        <xsl:template match="NewsItem" mode="output">
            <!-- Do something else -->
        </xsl:template>
    
    </xsl:stylesheet>
    

    This will work just the same as if you had copied the three included templates into the Main.xslt file where the <xsl:include /> instructions are.

    Using <xsl:import /> and <xsl:apply-imports /> is only necessary if you need to do some advanced overrides to an imported template. Otherwise, just stick with include - you can literally just rip out some templates from an existing stylesheet and put them in a separate file; then replace them in the original file with an <xsl:include /> instruction.

    Hope this clears up some confusion,

    /Chriztian

  • Kate 267 posts 610 karma points
    Aug 07, 2013 @ 11:49
    Kate
    0

    Thanks, it made ​​it a lot clear now. :-)

    I will test it out later today

Please Sign in or register to post replies

Write your reply to:

Draft