Search

Hey there! I have a simple basic question.

I have a XML like this

<pakalpojumi>
        <section id="14" handle="pakalpojumi">Pakalpojumi</section>
        <entry id="33">
            <bilde size="78 KB" path="" type="image/png">
                <filename>apdare.png</filename>
                <meta creation="2010-10-28T14:53:09+03:00" width="230" height="230" />
            </bilde>
            <nosaukums handle="apdares-darbi">Apdares darbi</nosaukums>
        </entry>
</pakalpojumi>

I don’t really get it how to include a picture in the XSLT.

    <div style="width: 230px; height: 230px; background: url({$root}/workspace/**FILENAMEHERE**)">
        <xsl:value-of select="nosaukums"/>
    </div>

Could somebody help me out? Thanks.

You must provide a complete XPath. This depends on in what scope your current template is. If your template is in the root (/), your XPath should be data/pakalpojumi/entry/nosaukums. If your template is already in data, this can be omitted in your XPath-expression:

<xsl:template match="data">
    <xsl:value-of select="pakalpojumi/entry/nosaukums" />
</xsl:template>

I don’t have a problem with that. I have problem with getting out the part - data/pakalpojumi/entry/bilde/filename into the line:

url({$root}/workspace/FILENAMEHERE)

I read your post as if you wanted the image inserted as a background image in the div where you have the FILENAMEHERE.

I’m uncertaind if the below is valid I haven’t tested, but it should be possible to create the style artibute this way making it possible to add en xsl statement inside.

<div>
  <xsl:attribute name="style">width: 230px; height: 230px; background: url({$root}/workspace/<xsl:value-of select="bilde/filename" />)
  </xsl:attribute>
<xsl:value-of select="nosaukums"/>
</div>

If you are in the right scope and value-of is returning “Apdares darbi”, then you can try this to get get the filename:

<div style="width: 230px; height: 230px; background: url({$root}/workspace/{bilde/filename})">
    <xsl:value-of select="nosaukums"/>
</div>

Oleae’s is the way to do it. I was overcomplicating things.

Thanks, it really worked! :)

Sorry, didn’t read you first post too good. ;-)

Actually, you should also include the path-attribute in your XPath, in case the file is located outside your physical workspace-folder (which is the case if you decide to create a dedicated uploads-folder in the workspace-folder (recommended)):

background: url({$root}/workspace{bilde/@path}/{bilde/filename})

Okay, thanks. I just created folder workspace/images for uploaded images.

And yeah. Now I don’t really understand how to select just one entry from XML.

<pakalpojumi-sub>
    <section id="14" handle="pakalpojumi">Pakalpojumi</section>
    <entry id="34">
        <nosaukums handle="vispariga-buvnieciba">vispariga buvnieciba</nosaukums>
        <bilde size="54 KB" path="/bildes" type="image/png">
            <filename>buvnieciba.png</filename>
            <meta creation="2010-10-28T17:01:29+03:00" width="230" height="230" />
        </bilde>
        <link-name handle="buvnieciba">buvnieciba</link-name>
    </entry>
</pakalpojumi-sub>

(theres other entries too, but I just left this one)

I have a page with URL param “link-name” which dominates on URL

someurl/service/link-name

in this case its:

someurl/service/buvnieciba

But how I can just fetch that one entry with current link-name.

like:

<xsl:if test="link-name = {$link-name}">
    <h1><xsl:value-of select="nosaukums"/></h1>
</xsl:if>

The only thing - this option doesn’t work - it gives error.

The only thing - this option doesn’t work - it gives error.

What’s the error?

General
Compile
XSLTProcessor::importStylesheet(): Invalid expression
XSLTProcessor::importStylesheet(): xsl:if : could not compile test expression 'link-name = {$link-name}'
XSLTProcessor::transformToXml(): No stylesheet associated to this object
services.xsl
Line 7
XSLTProcessor::importStylesheet(): compilation error: file file:///D:/AppServ/www/cms/workspace/utilities/services.xsl line 7 element if

Try this…

<xsl:if test="link-name/@handle={$link-name}">
    <h1><xsl:value-of select="nosaukums"/></h1>
</xsl:if>
General
Compile
XSLTProcessor::importStylesheet(): Invalid expression
XSLTProcessor::importStylesheet(): xsl:if : could not compile test expression 'link-name/@handle={$link-name}'
XSLTProcessor::transformToXml(): No stylesheet associated to this object
services.xsl
Line 7
XSLTProcessor::importStylesheet(): compilation error: file file:///D:/AppServ/www/cms/workspace/utilities/services.xsl line 7 element if

You shouldn’t use curly braces in this context.

(Okay, it’s corrected above)

So sorry, I totally missed the curly braces! No curly braces around $link-name. Try this…

<xsl:if test="link-name/@handle=$link-name">
    <h1><xsl:value-of select="nosaukums"/></h1>
</xsl:if>

Doh! Looks like I was too slow to respond. Nils beat me to the punch. Thanks Nils! Sorry I missed that one.

it worked! I spent about an hour trying to figure this out. 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