Search

Hello,

Im studying the standard workspace expecially the archive section. It looks like this : link text

Now I don't understand one thing. In the section where archive is written. The rule after that is <apply-templates="year/month"> But I can't find anywhere where the template year/month is written.

Can anyone explain how this works.

Roelof

This one on line 5

<apply-templates="year/month">

says: "Hey, XSL-processor, from this point on, for all nodes year/month that you can find, apply all templates that match these nodes."

On line 8, this

<xsl:template match="month">

says: "Hey, XSL-processor, I have something to apply for whatever nodes called month you have in your memory. Use me, please!"

Line 5 wants to apply "year/month". "year/month" and "month" can match that rule. On line 8 you have template match="month" which is applied.

Rule of thumb (@ all XSL pros, no priorities involved, includes, imports and whatever ;) ):

Given

<xsl:apply-templates select="continent/country/city" />

XSL-processor will first search and apply :

<xsl:template match="continent/countrycity">...</xsl:template>

If it can't find it, then will search and apply :

<xsl:template match="country/city">...</xsl:template>

If it can't find it, then will search and apply :

<xsl:template match="city">...</xsl:template>

If it can't find it, sky will fall. Try it :)

Oke,

A node is the same as a article ?

So In that template it will do this

First I will search to a template called year/month. That fails so I will look at a template called month which is present. So if I want to make a year/month archive menu. I have to change the month to a year/month template.

A node is the same as a article?

A node is a general term used to describe XML. In your example year and month are both nodes; more specifically, they are elements.

Reread the post above regarding your assumption because your change is not necessary unless you have competing templates.

I don't have competiting templates. I'm only trying to make a menu like this blog archive : link text

Roelof

roelof,

you should start to apply templates from node 'year'. add new template with match="year", and then apply templates for 'month' from it in a same fashion.

something like this: http://pastie.org/2817546

I now see a white screen and nothing else. I can see in xml that the right year and months are found. See the whole xml : link text

I found the solution : adding a include to master.xml.

But I get wierd output now as you can see here : link text

I hope someone can help me figure out where this wierd input is coming from.

You're requesting the processor to applying a template that doesn't exist. Make sure you have a matching template for all your selects.

sorry, but I don't see it. I begin in master.xsl That points to archive.xsl which is present. In archive.xsl there is a select to get-archive.xsl which is also present In get-archive there is a select year. There is also a match year. In year there is a select month And also a match month. In match month there is a select entry. And also a match month/entry.

So as far as I can see all selects are a match. But still I see a content area with the same text as the menu.

The fact that you are seeing extra content being outputted to the result screen indicates that XSLT is selecting bits of your XML where there are no matches for.

In XSLT, if you select something and there is no matching template, XSLT will simply dump the text portions out to the result screen.

I suggest you take each of the select statements out, one at a time and see which select statement is causing the extraneous data output.

Maybe a stupid question. But can I take a select out by putting a # before it.

In XSLT comments are generated the same as in HTML by wrapping the content in

<!-- ... -->

Found it. This piece of code does it : <xsl:template match="year"> <!-- "." means 'current node', in that case it is year --> <xsl:value-of select="."/> <ul> <xsl:apply-templates select="month"/> </ul> </xsl:template>

Expecially this sentence <xsl:value-of select="."/>

But if I deleted it then no output at all.

How can I solve this ?

I think you want to see the year/month-number, right? You should change <xsl:value-of select="."/> to <xsl:value-of select="@value"/>.

it works. Thank you. I try the same with the month which wil be the url to the archive but then it don't work. The xslt I have is this : <xsl:template match="month"> <ul class="list"> <li class="month"> <a href="{$root}/articles/{@value/@handle}/"> <xsl:value-of select="@value"/> </a> </li> </ul> </xsl:template>

I doubt an expression like @value/@handle will ever be valid. :-)

but month/@handle will also not work. I tried that already.

The element doesn't have an attribute @handle, only @value:

<month value="10">
   ...
</month>

So if I want to have a url like this test.tamarawobben.nl/year/month I have to use @value twice ?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details