Search

Hi guys, this time I searched the depths of the forum and couldn’t solve my problem.

Here’s the thing: I have a page that shows one pic of a gallery and have arrows to navigate to both next and previous images.

The gallery and the pic are choosed by URL Paremeters, so my URL look something like this: mywebsite.com/albuns/{$album-id}/{$photo-id}

The Flickr API, generated for me the following XSL:

<photoset id="1">
    <photo id="1"/>
    <photo id="2"/>
    <photo id="3"/>
    <photo id="4"/>
    <photo id="5"/>
</photoset>

So, when I’m at a page showing the photo #3 (mywebsite.com/albuns/1/3). I’d like to populate the href of the previous and next links with the URL of the photos #2 and #4.

I’ve tried so many possibilities here without success. I think it maybe achieved by using variables, but I just don’t know how to use them in this case!

tia

What’s the XSL you’re using?

what is the code which are you using there

You’re looking for the preceding-sibling and following-sibling axis:

<a href="{$root}/albuns/{$album-id}/{preceding-sibling::photo[1]/@id}/" />

and

<a href="{$root}/albuns/{$album-id}/{following-sibling::photo[1]/@id}/" />

Thank you phoke that was exactly what I was looking for. I’m just learning how to work with parameters and other stuff, so in times I get confused with the correct syntax.

For those who asked, my XSL look like this:

<div class="photo-view">
    <div class="prev">
        <xsl:for-each select="/data/listar-fotos/photoset/photo">
            <xsl:if test="@id = $foto | ">
                <a href="{$root}/categoria/album/foto/{$album}/{preceding-sibling::photo[1]/@id}/"></a>
            </xsl:if>
        </xsl:for-each>
    </div>
    <div class="next">
        <xsl:for-each select="/data/listar-fotos/photoset/photo">
            <xsl:if test="@id = $foto">
                <a href="{$root}/categoria/album/foto/{$album}/{following-sibling::photo[1]/@id}/"></a>
            </xsl:if>
        </xsl:for-each>
    </div>
    <div class="image">
        <xsl:for-each select="/data/listar-fotos/photoset/photo">
            <xsl:if test="@id = $foto">
                <img src="{./@url_o}"/>
            </xsl:if>
        </xsl:for-each>
    </div>
    <div class="extras">
        ...
    </div>
</div>

Glad I could help. Also, I’ve found that you have a lot of overhead in your XSLT.

First of all, all those for-eaches and ifs can be done in Xpath as well:

<div class="photo-view">
    <div class="prev">
        <a href="{$root}/categoria/album/foto/{$album}/{/data/listar-fotos/photoset/photo[@id = $foto]/preceding-sibling::photo[1]/@id}/"></a>
    </div>
    <div class="next">
        <a href="{$root}/categoria/album/foto/{$album}/{/data/listar-fotos/photoset/photo[@id = $foto]/following-sibling::photo[1]/@id}/"></a>
    </div>
    <div class="image">
        <img src="{/data/listar-fotos/photoset/photo[@id = $foto]/@url_o}"/>
    </div>
    <div class="extras">
        ...
    </div>
</div>

Secondly, you could make use of apply-templates and template match to shorten and DRY up your code a little bit more:

Define a template like

<xsl:template match="photo">
    <div class="photo-view">
        <div class="prev">
            <a href="{$root}/categoria/album/foto/{$album}/{preceding-sibling::photo[1]/@id}/"></a>
        </div>
        <div class="next">
            <a href="{$root}/categoria/album/foto/{$album}/{following-sibling::photo[1]/@id}/"></a>
        </div>
        <div class="image">
            <img src="{@url_o}"/>
        </div>
        <div class="extras">
            <!-- ... -->
        </div>
    </div>
</xsl:template>

And call it using

<xsl:apply-templates select="/data/listar-fotos/photoset/photo[@id = $foto]" />

That way the “what data I want to show” (the select-statement in your apply-templates) is seperated from “what it’s actually going to look like” (the content of your template match).

Livin’ and learnin’! lol

Thanks again phoque

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