Search

Hi, I’m trying to merge the information from a section link and a section. I’ll elaborate.

In the site I’m working on two languages are displayed side by side. The section category contains the category name in both languages and is linked to the articles section.

From an article list page I need to display each article section in both languages. The xml I get from just the articles section only gives me one language so I need another DS to fetch both categories names, right?

Now, my xml look something like this

<data>
    <articles>
        <entry>
            <title>Hello world</title>   
            <category>
                <item id="2">World</item>
            </category>
        </entry>
    </articles>
    <categories>
        <entry id="2">
            <name>World</nome>
            <name-it>Mondo</nome-it>
    </categories>
</data>

In my articles xsl I’d like to call a template every time I need to put a category name, something like this doesn’t work though.

<xsl:template match="articles/entry">
            <xsl:call-template name="category">
                <xsl:with-param name="id" select="category/item/@id"/>
            </xsl:call-template>
</xsl:template>

<xsl:template name="category" match="/categories">
    <xsl:param name="id"/>
    <xsl:value-of select="entry[@id=$id]/name"/> - <xsl:value-of select="entry[@id=$id]/name-it"/>
</xsl:template>

When I call the template I’m in articles/entry, how do I get to categories in the xml?

ps. It doesn’t work either without the wild XPath selection/filter (I just wanted to see if you guys liked it)

Hi iltrico,

If you need to pull out the Cat name, you could try something like this in the context of your entry:

<param name='cat-id' select='category/item/@id' />
<value-of select='/data/categories/entry[@id = $cat-id]/name' />

But how could I achieve something like this from another context, like “articles/entry”.

What I’d really like to do is to access data/category from a template that matches data/articles; is it possible or am I missing some key xsl concept?

Unless I’m misunderstanding, you should be able to reference any node that you like from any context as long as you give an absolute path from the root by having a leading slash (as @ashooner has done above e.g. /data/categories….)

Now I got it, thanks a lot!

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