Search

How can I select my content according to the attribute value? I have now the following XSLT code:

<xsl:apply-templates select="page[@handle='the-project']" />

Offcourse, I want this selector to only choose the page elements that correspondent to the following xml:

<page handle="the-project">
    <name>Name</name>
    <content>...</content>
</page>
<page handle="some-other-name">
    <name>Name</name>
    <content>...</content>
</page>

So in this example only the first page node should get selected, not the other one with handle=”some-other-name”.

That’s correct. What’s your question? :-)

Well, my code:

<xsl:apply-templates select="page[@handle='the-project']" />

doesn’t work! It just select every page, not looking at the handle!

Are you sure that you are in the right context when selecting page[@handle='the-project'] - maybe you are applying your template from the wrong node.

Hm, I noticed indeed that my selector is probably right, but it seems there is an error in my template. Can’t seem to find it however. I’m quite new to XSLT. Perhaps somebody here can see why I can’t get the desired result?

This is my XSLT: http://pastie.org/821559

This is my XML: http://pastie.org/821566

And this is my (undesired) result: http://pastie.org/821569

Your code

<xsl:apply-templates select="page[@handle='the-project']" />

just works fine. The problem seems to lie in your matching template.

How should the end result look like?

It should look like this: http://pastie.org/821577, but as you can see, all the HTML gets placed in the first div class=”subMenu”

Okay, that’s a tough task if you’re just starting with XSL. Maybe I’ll find some time later today and have a deeper look at it (or someone else here in the forum will guide you trough the sorting).

Thank you!

I think you’ve over-complicated things a little bit. You can create another Datasource that selects your subpage-categories and do it like this: http://pastie.org/821601.

I’ve tried to explain what I am doing in the comments:

Loop Toppages
    Loop Categories from second DS
        Loop Subpages
    /Loop
/Loop

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