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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.