XSLTProcessor wrong output?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eiri
Forum Newbie
Posts: 1
Joined: Tue Jan 13, 2009 2:13 pm
Location: Amsterdam, NL

XSLTProcessor wrong output?

Post by eiri »

Hi,

I have a question about the XSLTProcessor class (PHP Version 5.2.4, builtin
xls version 1.1.17):

I trying to generate a google kml file from a gpx file. I created an 1.0
XSLT with Altova Mapforce. This creates below xslt file. As you can see it
creates a namespace-alias tag, that should replace the "n:" namespace to the
default (no namespace) during the processing. However, when I execute the
xslt with a valid gpx file, it keeps the "n:" namespace. I need it without
any namespace.

Does anyone knows what went wrong or how I can avoid this. I cannot remove
the namespace-alias rule from the xslt or update or change my xslt processor
in php.

Thanks!

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:n="http://www.opengis.net/kml/2.2"
xmlns:n2="http://www.topografix.com/GPX/1/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
exclude-result-prefixes="n2 xs xsi xsl"
xmlns="http://www.opengis.net/kml/2.2">
<xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/n2:gpx">
<n:kml>
...
</n:kml>
</xsl:template>
</xsl:stylesheet>


Generates:

<?xml version="1.0" encoding="UTF-8"?>
<n:kml xmlns:n="http://www.opengis.net/kml/2.2"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns="http://www.opengis.net/kml/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2
C:/Users/Erwin/Projecten/MYWEBS~1/EiriMTB/xml/ogckml22.xsd">
...
</n:kml>

I used the following php snippit to generate the kml:

<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("xml/Zeltingen-Wolf.gpx");

$xpath = new DOMXPath($xmlDoc);

$xslDoc = new DOMDocument();
$xslDoc->load("xml/MappingMapToogckml22.xslt");
$proc = new XSLTProcessor();

$proc->importStylesheet($xslDoc);

echo $proc->transformToXML($xmlDoc);

?>
Post Reply