我正在使用撒克逊处理器在Kernow中测试我的xslt样式表。我总是使用xslt 1.0,因为simplexml甚至simpledom只能执行xslt 1.0。以下样式表在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);
那个样式表是php抛出一个编译错误,无法编译when语句<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>
我知道模板不完美且不易理解。在PHP中有这样的问题的任何经验?谢谢你的帮助!
罗伯特
答案 0 :(得分:2)
语法current()/local-name()
特定于XSLT 2.0。在XSLT 1.0中,您需要编写local-name(current())
。请注意,指定xsl:version =“1.0”并不能保证样式表符合XSLT 1.0。