Search

Hi,

I have a simple question about datasources and utilities. Can I have a utility script that will retrieve a part of a datasource?

I am building a site for a friend an since he has no skill formatting a text or page,I have created a section that contain some texts for its site. In a page editor (xsl), I have some graphics and some complex layouts, and I have some kind of 'place holders' for texts I want to display.

So in the page editor, I want to call an utility like 'get-text' or 'display-text' which will contain a parameter like 'text-unique-key' which is defined in my section (and only me can manage this field). I already know that a datasource must be associated to a page, this setup is already done. And in debug mode in the frontend, I can confirm that the xml contain all texts I need for build my page.

I am new the xsl language so I can't figure how I can realize my utility.

I hope my English is ok ;) Thanks

Yes you can use utilities to do get text - as long as the datasource is attached.

eg you might want to use

<xsl:call-template name='my-template'>
  <xsl:with-param name='text-unique-key' value='"key-name"'/>
</xsl:call-template>

Then you would have a matching template with that param that returns exactly what you want. I use the above for translations amongst other things.

Hi gunglien,

I am able to call (from my page xsl) my utiliy 'get-text' with the unique key parameter.

But I really don't know how to build my utility to select my targeted datasource (the node where the text-key is equal to my received parameter)

I think that it should look somethings like this...

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

<xsl:template name="get-text">
    <xsl:param name="text-identifier"/>

    <xsl:apply-templates select="data/texts[uniquekey = $text-identifier]"/>
</xsl:template>

<xsl:template match="texts">
    <xsl:value-of select="text"/>
</xsl:template>

</xsl:stylesheet>

??

Thanks

<xsl:template name="get-text">
    <xsl:param name="text-identifier"/>

    <xsl:apply-templates select="/data/texts/entry[uniquekey = $text-identifier]"/>
</xsl:template>

You should use the above assuming that texts is your datasource name and uniquekey is the field you want. And you have to match template /data/texts/entry to make sure you have an exact match. - If you need just value of you do not need to do apply templates but you can just do

<xsl:value-of select="/data/texts/entry[uniquekey = $text-identifier]/text"/>

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