I have awebsitewhichconsists of only onepage-a very longpage. I wouldlike it to bedivided intosections andeach sectionwill have its owndocumenttype. All the differentdocumenttypesmust thenbe assembled in one pagein the orderthey appearin the menu tree. Documenttypes can beused several timesand not in any particular order. Mymenutree looks like this:
Do you haveany idea howI do this-and does it make any sense what I have written:-)
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.
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)
Hopeit's okayif I askyoua secondquestion in thisthread. I have4 document typesto be inserted andthen Ithoughtif Icould makexsltfiles for eachtemplateand then justmake areference tothem.
<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)
One thingI notice is that your include of the tester.xslt file is included in the match. I believethat when you use an include, it mustbe include as I showhere.
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 ifI remember correctly it has tobe included up there.
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
<!--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>
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.
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 :-)
Hi Kate,
Yes that structure looks to make sense - the top level page can get its data by looping though all child nodes.
Im am not very good at xslt, so I was hoping that you could help me a little on the way ;-)
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
Hi Christian
Thanks for your help, but my big problem is that I dont know how to loop though all the child nodes :-)
/Kate
Hi Kate,
Here's a simple macro to get you started - feel free to add more questions :-)
/Chriztian
you are fast :-)
What do I do if my sections have different content?
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
Hi again,
That's the beautiful part - you can add templates for each kind of doctype if you need, e.g.:
/Chriztian
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 :-)
it works like a charm :-)
Again, Thanks for your help
/Kate
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
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
Thanks Chriztian
I will try it out :-)
I have made this simple exampel with 2 xslt files (import.xslt and tester.xslt)
import.xslt
tester.xslt
But I get an error when I try to save import.xslt
Can you help me with that? :-)
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.
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
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:
I forgot this line :-( Stupid me ;-)
Okay Kate, so you get it working now or?
/Dennis
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?
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:
This is the file I import the other files
Hope anybody can help :-)
/Kate
Hi Kate,
See this simplified version (I've left out all the namesace declarations etc. for easier scanning) :
Main.xslt
NavTemplates.xslt
OutputTemplates.xslt
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
Thanks, it made it a lot clear now. :-)
I will test it out later today
is working on a reply...