Jump to content

xml transformations (aka xslt) using php


surion

Recommended Posts

hi all

 

this is what i have:

the php script:

 

/* load the xml file and stylesheet as domdocuments */
$xsl = new DomDocument();
$xsl->load("style2.xsl");
$inputdom = new DomDocument();
$inputdom->load("van.xml");

/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);

/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
print $newdom->save("naar.xml");

 

this is the xsl stylesheet that i wrote, called style2.xsl:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet 
version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
xmlns:dyn="http://exslt.org/dynamic"
xmlns="http://www.w3.org/1999/xhtml"
extension-element-prefixes="exslt dyn">

<xsl:output 
	method="xml"
	version="1.0"
	omit-xml-declaration="no"
	encoding="UTF-8"
	standalone="yes"
	indent="yes"
	media-type="text/xml"/>

<xsl:template>
	<xsl:element name="products">
		<xsl:for-each select="Human_Nature_Content_NL/Article">
			<xsl:element name="product">
				<xsl:element name="name">
					<xsl:value-of select="@Name"/>
				</xsl:element>
			</xsl:element>
    </xsl:for-each>
	</xsl:element>
</xsl:template>

</xsl:stylesheet>

 

the van.xml file mentioned in the php code can be found here:

http://www.lodedesplancke.be/temp/van.xml.txt

 

now what my problem is: i get no errors at all when i run the php script, tough the output file "naar.xml" i get only contains:

 

<?xml version="1.0" encoding="UTF-8"?>

 

while it should actualy contain a list of product names, like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<products>
<product><name>name of product</name></product>
<product><name>name of product2</name></product>
...
and so on
...
</products>

 

does anyone have an idea what i could be doing wrong?

 

thanks in advance for any suggestion that could lead me to a solution of my problem

Link to comment
https://forums.phpfreaks.com/topic/78891-xml-transformations-aka-xslt-using-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.