Search

I need the last url param. One would think that the current-path param could shopped up with a substring to show its last part. But with a variable amount of url params this seems impossible to me.(substring always start from left of the string, never from right)

So, when I have params level2, level 3 and level4, the most efficient thing I can do is this snippet below?

    <xsl:if test="$level4 !=''">
<xsl:value-of select="$level4"/>
    </xsl:if>
    <xsl:if test="$level4 ='' and $level3 !=''">
<xsl:value-of select="$level3"/>
    </xsl:if>
    <xsl:if test="$level4 ='' and $level3 ='' and $level2 !=''">
<xsl:value-of select="$level2"/>
    </xsl:if>

I am doing the same for a project, but rather I am using choose when instead of if statements. I don't know if it is the optimal solution, but it works for me.

I've written a little extension that spits out each URL segment as $url-segment-n, I can link it up if people are interested in it. With your example, you could at the least simplify it so you only have to do it once. That is, setup an <xsl:param name="active-level"> in your master utility and output the last url param into that. That way you can just use $active-level elsewhere in your site.

You could try this technique: Widon't for XSLT.

It loops through a substring until it finds the last space and replaces it with a non-break space. I think the concept would work for your problem.

You've all piqued my curiosity. Are you using these url-params on a single Symphony Page that has n number of url params, or in some other way? I've thought about trying that, and basically bypassing Symphony's controller functionality.

A more succinct way might be to use a xsl:choose:

<xsl:variable name="$active-level">
    <xsl:choose>
        <xsl:when test="$level4 != ''">
            <xsl:value-of select="$level4"/>
        </xsl:when>
        <xsl:when test="$level3 != ''">
            <xsl:value-of select="$level3"/>
        </xsl:when>
        <xsl:when test="$level2 != ''">
            <xsl:value-of select="$level2"/>
        </xsl:when>
        <xsl:when test="$level1 != ''">
            <xsl:value-of select="$level1"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text>No level.</xsl:text>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

If the first condition isn't met, then it will fall through to the next, then the next, then the next etc. Saves you having to check all of the previous levels each time. As Max suggests, have wrapped this up into a variable so that it can be used globally.

thanks for all the suggestions, here is how I use it; I need to get the pre tag under a header the same as the last url param: The header is in the form of:

 <h2>Lokalised Header (Universal English Header used as handle)</h2>

the snippet:

<xsl:for-each select="
static-text/entry/text/h2[translate(normalize-space(substring-before(substring- after(text(),'('),')')),'ABCDEFGHIJKLMNOPQRSTUVWXYZ .,','abcdefghijklmnopqrstuvwxyz---') = $lastlevel]
|
static-text/entry/text/h3[translate(normalize-space(substring-before(substring-after(text(),'('),')')),'ABCDEFGHIJKLMNOPQRSTUVWXYZ .,','abcdefghijklmnopqrstuvwxyz---') = $lastlevel] 
|
static-text/entry/text/h4[translate(normalize-space(substring-before(substring-after(text(),'('),')')),'ABCDEFGHIJKLMNOPQRSTUVWXYZ .,','abcdefghijklmnopqrstuvwxyz---') = $lastlevel] 
">
<xsl:value-of select="following-sibling::pre" />
</xsl:for-each>

But surely there must be a more elegant way of doing this?

.

 <xsl:for-each select="
static-text/entry/text/*[substring(name(),1,1) ='h' and translate(normalize-space(substring-  before(substring-after(text(),'('),')')),'ABCDEFGHIJKLMNOPQRSTUVWXYZ .,','abcdefghijklmnopqrstuvwxyz--- ') = $lastlevel] 
">
<xsl:value-of select="following-sibling::pre" />
</xsl:for-each>

seems to work. However I need to limit the following sibling to under the selected header only, and not the next. Any ideas?

Makenosound, I would like to see your extension for use here

@newnomad: See the attached file. It was my first attempt at a Symphony extension and I haven't got the time to clean it up right not so it's a little messy; does what it's supposed to though.

Attachments

Thanks max, but how do you combine these params into the active (or last) param? Not sure how to nest params....this doesnt work for sure;

$url-segment-{$active-segment}

I haven't had a need for that, probably be best to just get the extension to output another parameter. Something like:

 $context['params']['active-segment-value'] = $request_uri[count($request_uri) - 1];

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