Search

Hey Folks,

I have the following working code

     $.backstretch([
     <xsl:for-each select='slider-images-for-background/entry/images/filename'>
       "http://www.mayerseedline.com/symphony/workspace/images/<xsl:value-of select='.'/>",
     </xsl:for-each>

     ], {
     fade: 750,
     duration: 10000
     });
   &lt;/script>
   <xsl:for-each select='slider-images-for-background/entry/images/filename'>
     <xsl:value-of select='.'/>
   </xsl:for-each>

I need to use it on all pages so I turned it into a utilities and imported it: But I don't know how to make it work :( I've imported it the utility looks like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="slider-images-for-background">
  &lt;script>
     $.backstretch([
     <xsl:for-each select='slider-images-for-background/entry/images/filename'>
       "http://www.mayerseedline.com/symphony/workspace/images/<xsl:value-of select='.'/>",
     </xsl:for-each>

     ], {
     fade: 750,
     duration: 10000
     });
   &lt;/script>
   <xsl:for-each select='slider-images-for-background/entry/images/filename'>
     <xsl:value-of select='.'/>
   </xsl:for-each>

</xsl:template>

</xsl:stylesheet>

<xsl:call-template name="slider-images-for-background" />

I'm not quite sure what you're trying to do here, but I'd rather put he image list in a data-attribute or a variable and parse it on the client. ...

<xsl:variable name="quote"><xsl:text>"</xsl:text></xsl:variable>
<xsl:variable name="imagelist">
  [
  <xsl:apply-templates select="slider-images-for-background/entry/images" mode="imagelist"/>
  ]
</xsl:variable>

<![CDATA[&lt;script>window.imageslist = ]]><xsl:value-of select="$imagelist"/><![CDATA;&lt;/script>]]>
...

<xsl:template match="entry/images" mode="imagelist">
  <xsl:value-of select="concat($quote, $root, 'workspace/images/', .,$quote)"/>
<xsl:if test="position() != last()">,</xsl:if>  
</xsl:template>

And in your client script just call your backstretch setup:

$.backstretch(window.imagelist)…

little update: This example should give you an idea

touchstone - so we are calling that template in the master.xsl since all the pages will call master.xsl? I had it as a utility that was called by each page?

I tried to add

<xsl:call-template name="slider-images-for-background" />

To the master page but got an error that the template was not found???

iwg - I just need to be able to single source the code.

got it, THANK!!!! Just called the template wrong.

hmmm that's not working. Is there a nesting issue?

In the master.xsl

I import background images utility then I call

<xsl:call-template name="slider-images-for-background" />

It applies the template but does not seem to evaluate this:

<xsl:for-each select='slider-images-for-background/entry/images/filename'>
       "http://www.mayerseedline.com/symphony/workspace/images/<xsl:value-of select='.'/>",
     </xsl:for-each>

However it (the call template) works perfectly if I call the template within any of the page.xsl.

within the script.

looks like an xpath issue so I did

<xsl:for-each select='**//**slider-images-for-background/entry/images/filename'>

instead of

<xsl:for-each select='slider-images-for-background/entry/images/filename'>

Prob wrong but it works.. :)

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