Search

I’m wondering how to use param’s inside the <apply-templates select=""/>. I have this xml document:


<agenda>
    <pagination total-entries="5" total-pages="1" entries-per-page="50" current-page="1" />
    <section id="3" handle="evenementen">Evenementen</section>
    <year value="2010">
        <month value="04">
            <entry id="39">
                <titel handle="zomermarkt">Zomermarkt</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="7">2010-04-18</datum>
                <lange-beschrijving mode="formatted"><p>
Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
        </month>
    </year>
</agenda>

And I have 2 param’s called $title and $url-maand. Now I want to filter my events on these parameters using the <xsl:apply-templates select="agenda/year[@value='2010']/month[@value='03']/entry" /> Using the parameters it should look like this: <xsl:apply-templates select="agenda/year[@value='$title']/month[@value='$url-maand']/entry" />

But it is not working, what am I doing wron?

You are treating your parameter names as strings:

<xsl:apply-templates select="agenda/year[@value='$title']/month[@value='$url-maand']/entry" />

should in fact be

<xsl:apply-templates select="agenda/year[@value=$title]/month[@value=$url-maand]/entry" />

I’ve tried your solution, but now I’m getting this error:

XSLT Processing Error This page could not be rendered due to the following XSLT processing errors. General Compile XSLTProcessor::importStylesheet(): Undefined variable XSLTProcessor::importStylesheet(): Failed to compile predicate XSLTProcessor::importStylesheet(): Undefined variable XSLTProcessor::importStylesheet(): Failed to compile predicate XSLTProcessor::transformToXml(): No stylesheet associated to this object agenda.xsl Line 72 XSLTProcessor::importStylesheet(): compilation error: file /home/bestemming/domains/bestemmingborgerodoorn.nl/publichtml/workspace/pages/agenda.xsl line 72 element template Line 72 XSLTProcessor::importStylesheet(): compilation error: file /home/bestemming/domains/bestemmingborgerodoorn.nl/publichtml/workspace/pages/agenda.xsl line 72 element template

Pretty much, you must already have $title and $url-maand defined somewhere.

So in the top level of your XSLT, <xsl:param name='title' /> and <xsl:param name='url-maand' /> should exist. When these are set, they will take on those values, otherwise they will be ‘nothings’.

The $url-maand and $title is set by the URL when I’m linking to /2010/?maand=03
$url-maand gets the 03 and $title gets the 2010.

I’ve looked inside my ?debug and there I saw the params.

What’s on line 72 of your agenda.xsl template?

<xsl:template match="agenda/year[@value='$title']/month[@value='$url-maand']/entry">

That was te old one, the new one with te same problem is: <xsl:template match="agenda/year[@value=$title]/month[@value=$url-maand]/entry">

OK. Could you post all of your XML and XSL (for the page you are having difficulty on) on pastie.org

@whgdesign, got it to work, instead of …

<xsl:template match="agenda/year[@value=$title]/month[@value=$url-maand]/entry">

Try just matching the entry without all the predicates.

<xsl:template match="entry">

Actually, I did an example to test your code out. Here’s the example xml based off of your code above…

<?xml version="1.0" encoding="UTF-8"?>
<agenda>
    <pagination total-entries="5" total-pages="1" entries-per-page="50" current-page="1" />
    <section id="3" handle="evenementen">Evenementen</section>
    <year value="2010">
        <month value="04">
            <entry id="39">
                <titel handle="zomermarkt">Zomermarkt</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="7">2010-04-18</datum>
                <lange-beschrijving mode="formatted"><p>
                    Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
            <entry id="40">
                <titel handle="zomermarkt">Example</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="2">2010-04-20</datum>
                <lange-beschrijving mode="formatted"><p>
                    Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
            <entry id="41">
                <titel handle="zomermarkt">Test</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="4">2010-04-22</datum>
                <lange-beschrijving mode="formatted"><p>
                    Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
        </month>
        <month value="05">
            <entry id="42">
                <titel handle="zomermarkt">Another Test</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="7">2010-05-02</datum>
                <lange-beschrijving mode="formatted"><p>
                    Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
        </month>
    </year>
</agenda>

Here’s the xslt…

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
    <xsl:output method="xml" 
        encoding="UTF-8" 
        indent="yes" 
        omit-xml-declaration="yes" 
        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

    <!-- your url-params -->
    <xsl:param name="title" select="2010"/>
    <xsl:param name="url-maand" select="04"/>
    <!-- your url-params, these value are being generated from your url parameters -->

    <xsl:template match="/">
        <html>
            <head>
                <title><xsl:value-of select="name(agenda)"/></title>
            </head>
            <body>
                <h1><xsl:value-of select="name(agenda)"/></h1>
                <xsl:apply-templates select="agenda/year[@value=$title]/month[@value=$url-maand]/entry" mode="agenda-entries" />
            </body>
        </html>
    </xsl:template>
    <xsl:template match="entry" mode="agenda-entries">
        <dl>
            <dt><xsl:value-of select="titel"/></dt>
            <dd><xsl:value-of select="datum"/></dd>
        </dl>
    </xsl:template>
</xsl:stylesheet>

That should transform out to be the following HTML…

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>agenda</title>
  </head>
  <body>
    <h1>agenda</h1>
    <dl>
      <dt>Zomermarkt</dt>
      <dd>2010-04-18</dd>
    </dl>
    <dl>
      <dt>Example</dt>
      <dd>2010-04-20</dd>
    </dl>
    <dl>
      <dt>Test</dt>
      <dd>2010-04-22</dd>
    </dl>
  </body>
</html>

The $url-maand and $title is set by the URL when I’m linking to /2010/?maand=03 $url-maand gets the 03 and $title gets the 2010.

I’ve looked inside my ?debug and there I saw the params.

Yes, but if you just go to the root of the page, ie. not with 2010 or ?maand set, the error will throw..

With this XML <xsl:param name="title" select="2010"/>. Note that that is looking for a node called 2010. For it to take on the string value, wrap it with quotes again, <xsl:param name="title" select="'2010'"/>.

Hey guy’s thanks for all the comments.
I’ll try to change my code tonight and then I’ll see if it works.
For now, thanks for all the help.

Maybe it’s better to explain my target here.

I want to show events by month, for example for the month April 2010. It has to be possible to go to the next and previous month. I’ve to try a lot to figure the best way out.
You guys helped me a lot so far, but maybe you can help me better with the xml and xslt file included.

Good luck :p

The XML

<agenda>
    <pagination total-entries="30" total-pages="1" entries-per-page="50" current-page="1" />
    <section id="3" handle="evenementen">Evenementen</section>
    <year value="2010">
        <month value="04">
            <entry id="39">
                <titel handle="zomermarkt">Zomermarkt</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="7">2010-04-18</datum>
                <lange-beschrijving mode="formatted"><p>
Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
        </month>
        <month value="05">
            <entry id="41">
                <titel handle="zomermarkt">Zomermarkt</titel>
                <korte-beschrijving mode="formatted"><p>Zomermarkt aan de Schoolstraat in Exloo.</p></korte-beschrijving>
                <datum time="00:00" weekday="7">2010-05-02</datum>
                <lange-beschrijving mode="formatted"><p>
Zomermarkt aan de Schoolstraat in Exloo.</p></lange-beschrijving>
            </entry>
        </month>
    </year>
</agenda>

The XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="../utilities/master.xsl"/>
<xsl:include href="../utilities/agendaheadlines.xsl"/>
<xsl:include href="../utilities/columns.xsl"/>
<xsl:include href="../utilities/slogan.xsl"/>
<xsl:param name="title" select="'2010'"/>
<xsl:param name="url-maand" select="'04'"/>
<xsl:template match="data">
        <div class="main agenda">
            <h2>Evenementen</h2>
            <xsl:apply-templates select="agenda/year[@value=$title]/month/entry" />
        </div>
        <div class="secondary agenda">
            <div class="clear month">
                <a>
                    <xsl:attribute name="class">
                        <xsl:text>arrowleft</xsl:text>
                    </xsl:attribute>
                    <xsl:attribute name="href">
                        <xsl:text>?maand=0</xsl:text>
                        <xsl:value-of select="$url-maand - 1"/>
                    </xsl:attribute>
                    <img src="{$workspace}/images/arrow_left.png" />
                </a>
                <h2>
                    <xsl:choose>
                        <xsl:when test="$url-maand = 1">
                            Januari <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:when test="$url-maand = 2">
                            Februari <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:when test="$url-maand = 3">
                            Maart <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:when test="$url-maand = 4">
                            April <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:when test="$url-maand = 5">
                            Mei <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:when test="$url-maand = 6">
                            Juni <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:when test="$url-maand = 7">
                            Juli <xsl:value-of select="$title"/>
                        </xsl:when>
                        <xsl:otherwise>
                            Geen maand!
                        </xsl:otherwise>
                    </xsl:choose>
                </h2>
                <a>
                    <xsl:attribute name="class">
                        <xsl:text>arrowright</xsl:text>
                    </xsl:attribute>
                    <xsl:attribute name="href">
                        <xsl:text>?maand=0</xsl:text>
                        <xsl:value-of select="$url-maand + 1"/>
                    </xsl:attribute>
                    <img src="{$workspace}/images/arrow_right.png" />
                </a>
            </div>
        </div>
        <div class="tertiary">
            <xsl:apply-templates select="columns" />
            <xsl:apply-templates select="slogan/entry" />
        </div>
</xsl:template>
<xsl:template match="agenda/year[@value=$title]/month/entry">
        <ul>
            <li class="agendaitem">
                <a class="popup" rel="width:800;">
                    <xsl:attribute name="href">
                        <xsl:text>#</xsl:text>
                        <xsl:value-of select="titel/@handle"/>
                    </xsl:attribute>
                    <p class="right readmore"><span>lees meer</span></p>
                    <div class="date">
                        <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="'%d+; '"/></xsl:call-template>
                        <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="' %d;'"/></xsl:call-template>
                        <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="' %m+;'"/></xsl:call-template>
                        <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="' %y+;'"/></xsl:call-template>
                    </div>
                    <h4><xsl:value-of select="titel"/></h4>
                    <p><xsl:value-of select="korte-beschrijving"/></p>
                </a>
                <div class="hidden">
                    <div class="agendapopup">           
                        <xsl:attribute name="id">
                            <xsl:value-of select="titel/@handle"/>
                        </xsl:attribute>
                        <div class="agendaitem">
                            <div class="date">
                                <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="'%d+; '"/></xsl:call-template>
                                <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="' %d;'"/></xsl:call-template>
                                <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="' %m+;'"/></xsl:call-template>
                                <xsl:call-template name="format-date"><xsl:with-param name="date" select="datum"/><xsl:with-param name="format" select="' %y+;'"/></xsl:call-template>
                            </div>
                            <h4><xsl:value-of select="titel"/></h4>
                            <p><b><xsl:copy-of select="korte-beschrijving"/></b></p>
                            <xsl:copy-of select="lange-beschrijving"/>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
</xsl:template>
</xsl:stylesheet>

<xsl:template match="agenda/year[@value=$title]/month/entry">

Your template match should be:

<xsl:template match="agenda/year/month/entry">

I’ll dig up a recent forum thread that explains why :)

EDIT: here you go

It’s still not working, maybe it’s better to use params without the URL tags.

Can someone help me?

Sorry to ask but what exactly is “not working”?

Does it show incorrect entries, do the params work at all?

Can someone help me?

We’re trying to, don’t worry. :-)

Is it an issue of grouping by month?

If so, try this…

http://getsymphony.com/discuss/thread/28297/1/#position-9

Hey Guys,

I got everything fixed. I’ve putted {$year}-{$month} inside the filter of my “Data Sources”. On my page I’ve putted year/month inside the “URL Parameters”.
On the xslt file I’ve placed above the template:

<xsl:param name="title" select="'2010'"/>
<xsl:param name="url-maand" select="'04'"/>

Inside the template I’ve placed: <xsl:apply-templates select="agenda/year[@value=$title]/month/entry" /> And I’ve made a matching template wit this code: <xsl:template match="agenda/year/month/entry">

Thank you all for helping me, some of you putted me to the good direction.

If you like it, you can take a look on: http://www.bestemmingborgerodoorn.nl/agenda/2010/04/

let's say you have any of param or variable

<xsl:variable name="ds-general" select="//industries"/>

then you're using it this way

<xsl:apply-templates select="$ds-general/entry" />

Is this a question?

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