Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:22:30+00:00 2026-06-13T21:22:30+00:00

I have an XSL file. I have a PHP file with a XSLTProcessor named

  • 0

I have an XSL file.

I have a PHP file with a XSLTProcessor named $bob.

I want to send to my xsl transformation some parameters.

So, I write this in my PHP file; for example :

$bob->setParameter('', 'message', 'hi');

In my XSL file, to get the parameter, I write this for example :

<xsl:param name="message" />

And if i want to display this param in my XSL, I do this :

<xsl:value-of select="$message" />

Here comes the problem.

I have to send to my XSL an undefined number of parameters, and I don’t know how to do it. I tried several solutions but they were not relevant. I want to send for example 3 messages to my XSL, and I want my XSL to use them to produce a code like this :

<messages>
    <message>Hi</message>
    <message>it's bob</message>
    <message>How are you ?</message>
</messages>

Do you have a solution for me ?
It will be very nice.
Sorry if my english has mistakes.
Thanks you and have a good day.

As asked, here is what I have and what I want to have :

(the following is separated)

Here is a simplified version of my original XML, named posts.xml :

<posts>
    <post id="post1" >
        <titre>Hey</titre>
        <motscles>
            <motcle>Batman</motcle>
            <motcle>Cats</motcle>
        </motscles>
    </posts>
</posts>

Here is the XML i want to have in final :

<posts>
    <post id="post1" >
        <titre>Hey</titre>
        <motscles>
            <motcle>Batman</motcle>
            <motcle>Cats</motcle>
        </motscles>
    </posts>
    <post id="post2" >
        <titre>Toto</titre>
        <motscles>
            <motcle>Superman</motcle>
            <motcle>Dogs</motcle>
            <motcle>Cake</motcle>
        </motscles>
    </posts>
</posts>

I obtained the information of the post (titre, motscles) by an HTML form.
So my php file get the information, and send it to my XSL file :

// initialize xml and xsl
$xml = new DOMDocument();
$xml->load('posts.xml');
$xsl = new DOMDocument();
$xsl->load('addpost.xsl');

// Initialize the XSLTProcessor
$addPost  = new XSLTProcessor();
$addPost->importStylesheet($xsl);

// Define parameters
$addPost->setParameter('', 'titre', $_POST['titre']);

// Get the modified xml
$xml = $addPost->transformToDoc($xml);

// Save the modified xml
$xml->save('posts.xml');

Here is a simplified version of my XSL :

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

    <xsl:param name="titre" />
    <xsl:param name="motscles" />

    <xsl:template match="posts" >
        <xsl:copy>

            <xsl:apply-templates select="@*" />
            <xsl:apply-templates select="@*|node()"/>

            <xsl:call-template name="post" />
        </xsl:copy>
    </xsl:template>

    <!-- Template de post -->
    <xsl:template name="post" >
        <post id="{$id}" >
            <titre><xsl:value-of select="$titre" /></titre>
            <motscles>
            </motscles>
        </post>
    </xsl:template>

    <!-- Copier les nodes et attributs récursivement -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*" />
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
   </xsl:template>  

</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:22:34+00:00Added an answer on June 13, 2026 at 9:22 pm

    Well decide on a separator character for your messages (i.e. a character that is ensured not to occur in a message), then pass in a string with the messages separated by that character e.g. if you choose | you pass in $bob->setParameter('', 'message', "Hi|It's Bob|How are you?");, then in your XSLT code to be used with libxslt use e.g.

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0"
      xmlns:str="http://exslt.org/strings"  
      exclude-result-prefixes="str">
    
    <xsl:param name="message"/>
    
    <xsl:variable name="msgs-rtf">
      <messages>
        <xsl:for-each select="str:tokenize($message, '|')">
           <message>
             <xsl:value-of select="."/>
           </message>
        </xsl:for-each>
      </messages>
    </xsl:variable>
    
    <xsl:template match="/">
      <xsl:copy-of select="$msgs-rtf"/>
    </xsl:template>
    
    </xsl:stylesheet>
    

    As far as I know that extension function str:tokenize is supported in libxslt which PHP 5 uses for XSLT so you should be able to use it. Or you need to write a template that does the tokenization in XSLT itself

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xsl file where i need to use parameters from an external
i have a xml and a xsl file. i want output of xsl in
I have a XSL file to transfer another XSL file. I want the namespace
I have this PHP web application. It has a link to an XML file
I have an XML catalog data and an XSL file to visualize this catalog
I have a problem with namespace position in result xml file after xsl transformation.
I have xsl file whose size is approx 12kb, i want to zip it.
I have to make xPath dynamical, based on my request attributes in XSL file
I have an XSL style sheet for which I need to add some custom
I have two xsl file each for different type of machines for various unix

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.