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

  • SEARCH
  • Home
  • 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 82985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:42:09+00:00 2026-05-10T21:42:09+00:00

I have a custom XML schema defined for page display that puts elements on

  • 0

I have a custom XML schema defined for page display that puts elements on the page by evaluating XML elements on the page. This is currently implemented using the preg regex functions, primarily the excellent preg_replace_callback function, eg:

... $s = preg_replace_callback('!<field>(.*?)</field>!', replace_field, $s); ...  function replace_field($groups) {   return isset($fields[$group[1]) ? $fields[$groups[1]] : ''; } 

Just as an example.

Now this works pretty well… so long as the XML elements aren’t nested. At this point it gets a whole lot more complicated, like if you have:

<field name='outer'>   <field name='inner'>     ...   </field> </field> 

You want to make sure you replace the innermost field first. Judicious use of greedy/non-greedy regex patterns can go some of the way to handling these more complicated scenarios but the clear message is that I’m reaching the limits of what regex can reasonably do and really I need to be doing XML parsing.

What I’d like is an XML transformation package that:

allows me to conditionally evaluate/include the contained document tree or not based on a callback function ideally (analagous to preg_replace_callback); can handle nested elements of the same or different types; and handles attributes in a nice way (eg as an associative array).

What can help me along the way?

  • 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. 2026-05-10T21:42:10+00:00Added an answer on May 10, 2026 at 9:42 pm

    PHP’s XSLTProcessor class (ext/xsl – PHP 5 includes the XSL extension by default and can be enabled by adding the argument --with-xsl[=DIR] to your configure line) is quite sophisticated and allows among other things the use of PHP functions within your XSL document by using the XSLTProcessor::registerPHPFunctions() method.

    The following example is shamelessly pinched from the PHP manual page:

    $xml = '<allusers>  <user>   <uid>bob</uid>  </user>  <user>   <uid>joe</uid>  </user> </allusers>'; $xsl = '<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      xmlns:php="http://php.net/xsl"> <xsl:output method="html" encoding="utf-8" indent="yes"/>  <xsl:template match="allusers">   <html><body>     <h2>Users</h2>     <table>     <xsl:for-each select="user">       <tr><td>         <xsl:value-of              select="php:function(\'ucfirst\',string(uid))"/>       </td></tr>     </xsl:for-each>     </table>   </body></html>  </xsl:template> </xsl:stylesheet>'; $xmldoc = DOMDocument::loadXML($xml); $xsldoc = DOMDocument::loadXML($xsl);  $proc = new XSLTProcessor(); $proc->registerPHPFunctions(); $proc->importStyleSheet($xsldoc); echo $proc->transformToXML($xmldoc); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using the primary key is fine. What exactly are you… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Personally, I would probably just use subversion from the command… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer I would say no it should not share the flag.… May 11, 2026 at 10:50 pm

Related Questions

By adding a custom handler to the SiteMapResolve event, I can update sitemap url's
What do I want to achieve? We are currently working on a PHP project
The following questions are about XML serialization/deserialization and schema validation for a .net library
I have a class that represents credit card details. To represent valid from and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.