Transform one XML tag into another by PHP and XSL


// XML/XSL: Transform one tag into another
// You need to have php_xsl.dll in your php extenstions

function transform($xml, $xsl) {
   $xslt = new XSLTProcessor();
   $xslt->importStylesheet(new SimpleXMLElement($xsl));
   return $xslt->transformToXml(new SimpleXMLElement($xml));

$sXml  = ‘<xml><sudhir><image id=”model_jpg” name=”model_jpg”>

$sXsl  = ‘<xsl:stylesheet
    xmlns:xsl=”; version=”1.0″>
    <xsl:output method=”xml”/>

    <xsl:template match=”image/init_from”>
        <init_from2><xsl:value-of select=”.”/></init_from2>

    <xsl:template match=”* | @*”>
        <xsl:copy><xsl:copy-of select=”@*”/><xsl:apply-templates/></xsl:copy>

echo transform($sXml, $sXsl);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: