Xslt does not work in php but saxon did
i am testing my xslt stylesheets sometimes in Kernow with a saxon processor. I always use xslt 1.0 because simplexml or even simpledom can only execute xslt 1.0. the following stylesheet does not work in php:
$tagsXml=simpledom_load_file('...xml');
$dom_sxe=dom_import_simplexml($tagsXml);
$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);
$proc = new XSLTProcessor();
$xsl = new DOMDocument;
$xsl->load('...xslt');
$proc->importStylesheet($xsl);
$newXml = $proc->transformToXml($dom);
thats the stylesheet were php throw an compilation error that is not possible to compile the when statement <xsl:when test="count($ctag/ancestor::*[local-name()=current()/local-name() and text()=current()/text()]|$ctag/descendant::*[local-name()=current()/local-name() and text()=current()/text()])>0">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" exclude-result-prefixes="xs">
<xsl:output method="xml"/>
<xsl:output indent="no"/>
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="tag">
</xsl:template>
<xsl:template match="related">
<xsl:for-each select="descendant::*[name()!='right' and name()!='rating' and name()!='id' and name()!='geo']">
<xsl:variable name="ctag" select="."/>
<xsl:variable name="memxlvl" select="count(//*[max(count(ancestor-or-self::*)) and count(ancestor-or-self::*[.=current()/.]) >0]/ancestor-or-self::*)"/>
<xsl:variable name="melvl" select="count(current()/ancestor::*)"/>
<!--<xsl:value-of select="$memxlvl - $melvl"/>-->
<!--<xsl:value-of select="开发者_运维百科(($memxlvl - $melvl) >= 0)*($memxlvl - $melvl) - not(($memxlvl - $melvl) >= 0)*($memxlvl - $melvl)"/>-->
<xsl:for-each select="current()/ancestor::related/descendant::*[text()!=current()/text() and name()!='right' and name()!='rating' and name()!='id' and name()!='geo']">
<tagconn me="{$ctag/text()}" friend="{./text()}">
<xsl:choose>
<xsl:when test="count($ctag/ancestor::*[local-name()=current()/local-name() and text()=current()/text()]|$ctag/descendant::*[local-name()=current()/local-name() and text()=current()/text()])>0">
<xsl:variable name="fmxlvl" select="count(//*[max(count(ancestor-or-self::*)) and count(ancestor-or-self::*[.=current()/.]) >0]/ancestor-or-self::*)"/>
<xsl:variable name="flvl" select="count(current()/ancestor::*)"/>
<xsl:value-of select="((($memxlvl - $melvl)-($fmxlvl - $flvl)) >= 0)*(($memxlvl - $melvl)-($fmxlvl - $flvl)) - not((($memxlvl - $melvl)-($fmxlvl - $flvl)) >= 0)*(($memxlvl - $melvl)-($fmxlvl - $flvl))"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fmxlvl" select="count(//*[max(count(ancestor-or-self::*)) and count(ancestor-or-self::*[.=current()/.]) >0]/ancestor-or-self::*)"/>
<xsl:variable name="flvl" select="count(current()/ancestor::*)"/>
<xsl:value-of select="((($memxlvl - $melvl)-($fmxlvl - $flvl)) >= 0)*(($memxlvl - $melvl)-($fmxlvl - $flvl)) - not((($memxlvl - $melvl)-($fmxlvl - $flvl)) >= 0)*(($memxlvl - $melvl)-($fmxlvl - $flvl))+((($memxlvl - $melvl) >= ($fmxlvl - $flvl)))*($memxlvl - $melvl) - not((($memxlvl - $melvl) < ($fmxlvl - $flvl)))*(($fmxlvl - $flvl))"/>
</xsl:otherwise>
</xsl:choose>
</tagconn>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="alltags">
<items>
<xsl:apply-templates select="descendant::related"/>
</items>
</xsl:template>
</xsl:stylesheet>
i know that the template is not perfect and not easy to understand. any experience with such problem in php? thanks for your help!
Robert
The syntax current()/local-name()
is specific to XSLT 2.0. In XSLT 1.0 you would need to write local-name(current())
. Note that specifying xsl:version="1.0" is no guarantee that your stylesheet is conformant to XSLT 1.0.
精彩评论