我正在使用撒克遜處理器測試我的xslt樣式表有時在Kernow中。我總是使用xslt 1.0,因爲simplexml甚至simpledom只能執行xslt 1.0。下面的樣式表並不在PHP工作:Xslt在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拋出一個編譯錯誤,那是不可能的編譯時聲明<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中遇到這種問題的任何經驗?謝謝你的幫助!
羅伯特
這個測試對我來說看起來不錯,也許這是一個逃避角色的問題。那麼如何用'!='替換'>'來查看是否屬於這種情況? – rsp 2011-04-30 18:43:13
好吧,我試過這樣的逃生場景,但它並沒有結束!謝謝你的幫助.. – rokdd 2011-04-30 21:02:56