2010-08-10 28 views
0

我试图有条件地显示HTML页面的内容,具体取决于是否为已识别的公司生成文档。XSL处理器堆栈溢出 - 无法理解为什么

然而,转型不工作,我不明白为什么:(我使用MSXML3.0作为变压器和氧气作为IDE,它给我下面提出的错误。

我做的是构建一长串所有公认的公司(默认和额外的,如果有的话),然后将它们分成<token>元素,这些元素存储在$companiesKnownList变量中,要确定一个公司是否在该列表中,我计算它发生的次数:

count($companiesKnownList/token[normalize-space(.) = $productName]) &lt; 1 

如果小于1,那么公司不会出现在$companiesKnownList var因此不被承认。否则,如果它出现在$companiesKnownList变量一次或多次它是一家公认的公司。然而,这是它打破,并显示以下错误:

Description: Code: 0x80004005 
Description: The XSL processor stack has overflowed - probable cause is infinite template recursion. 
Description: The transformer process ended with code: 1 

我发现,如果我的XML得到了一个获此殊荣的企业,前@ProductName="ski"然后转型失败,堆栈溢出。如果我有一家无法识别的公司,例如@ProductName="bla",则会显示转换工作和文本,它不是公认的公司。

我不明白有效的公司出了什么问题。如果你能帮助我,我将不胜感激。我一直盯着它看了一天......没有任何进展:S

谢谢!

这里是我的样式表:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:str="http://exslt.org/strings" 
extension-element-prefixes="msxsl str" 
version="1.0"> 

<!-- Taken from http://www.exslt.org/str/functions/tokenize/index.html --> 
<xsl:import href="str.tokenize.template.xsl"/> 

<!-- normalize and lowcase product name --> 
<xsl:variable name="productName" 
    select="normalize-space(translate(/Doc/@ProductName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))"/> 

<!-- default recognised companies for all docs --> 
<xsl:variable name="defaultRecognisedCompanies" select="'ski, holiday, summer trips'"/> 

<!-- Determine what companies to generate a doc for --> 
<xsl:variable name="companiesKnownListRaw"> 
    <xsl:call-template name="recognisedCompanies"/> 
</xsl:variable> 

<xsl:variable name="companiesKnownList" select="msxsl:node-set($companiesKnownListRaw)"/> 


<!-- Lists recognised companies for a document to be generated for --> 
<xsl:template name="recognisedCompanies"> 
    <xsl:call-template name="recognisedCompaniesListForDocument"/> 
</xsl:template> 


<xsl:template name="recognisedCompaniesListForDocument"> 
    <xsl:param name="defaultCompanies" select="$defaultRecognisedCompanies"/> 
    <xsl:param name="isUseDefaultsCompanies" select="true()"/> 
    <xsl:param name="extraCompanies" select="''"/> 


    <xsl:variable name="allCompaniesRaw"> 
     <xsl:call-template name="str:tokenize"> 
      <xsl:with-param name="string"> 
       <xsl:choose> 
        <!-- keep default companies --> 
        <xsl:when test="$isUseDefaultsCompanies = 'true'"> 
         <xsl:value-of select="concat($defaultCompanies, ', ', $extraCompanies)"/> 
        </xsl:when> 
        <!-- discard default companies --> 
        <xsl:otherwise> 
         <xsl:value-of select="$extraCompanies"/> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:with-param> 
      <xsl:with-param name="delimiters" select="','" /> 
     </xsl:call-template> 
    </xsl:variable> 

    <!-- Normalize token's value and discard empty values --> 
    <xsl:for-each select="msxsl:node-set($allCompaniesRaw)/token"> 
     <xsl:if test="normalize-space(.) != ''"> 
      <token> 
       <xsl:value-of select="normalize-space(.)"/> 
      </token> 
     </xsl:if> 
    </xsl:for-each> 
</xsl:template> 


<!-- Construct HTML doc. Display appropriate message for a company if it's recognized or not --> 
<xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" 
    doctype-system="http://www.w3.org/TR/html4/loose.dtd" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/Doc"> 
    <html> 
     <xsl:choose> 
      <!-- Not recognised company --> 
      <!-- There is something wrong with the count conditions, and I don't understand what :(--> 
      <xsl:when test="count($companiesKnownList/token[normalize-space(.) = $productName]) &lt; 1"> 
       <body> 
        <div align="center"> 
         This type of company is NOT recognised for this document. 
        </div> 
       </body> 
      </xsl:when> 
      <!-- Recognised company --> 
      <xsl:otherwise> 
       <body> 
        <div align="center"> 
         This type of company is recognised for this document. 
        </div> 
       </body> 
      </xsl:otherwise> 
     </xsl:choose> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

XML是喜欢的东西很简单:

在这个例子中,ski是公认的公司,但转型失败。 <?xml version="1.0" encoding="UTF-8"?> <Doc ProductName="ski" />

在此示例中,bla不是公认的公司,并且转换成功显示文本:“此类公司不被识别为此文档。” <?xml version="1.0" encoding="UTF-8"?> <Doc ProductName="bla" />

+0

这个问题有些*错误*。看我的回答 – 2010-08-10 17:22:22

回答

1

您需要添加命名模板str:tokenize的实施。检查在http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl

杰尼·坦尼森实施之后,将其添加为样式表顶部元素,以正确的href:

<xsl:include href="str.tokenize.template.xsl"/> 

有了改变(和关闭您的最后一个模板)与该输入:

<Doc ProductName="ski" /> 

输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
    <body> 
     <div align="center"> 
         This type of company is recognised for this document. 
     </div> 
    </body> 
</html> 
+0

@Alejandro - 谢谢你的发现!我在原始样式表中确实有这个 - 我试图在这里简化它,错过了结束标记和导入。傻我呢!那时还有其他问题出错了。再次感谢。 – DashaLuna 2010-08-11 13:43:00

+0

@Ajjandro - 是的,它也适用于我。必须是我在''内做的其他事情(因为这个例子只是简化的文本 - 在我到达''标签之前,我认为我的逻辑中有些东西是错误的)。谢谢你的时间寻找和回答。我会检查其他问题。谢谢 – DashaLuna 2010-08-11 16:26:25

0

MSXML(任何版本)不支持EXSLT - 并且XSLT处理器产生错误消息。

请问您是否纠正了问题,以便只有真实的信息存在?

+0

编辑答案“MSXML(任何版本)不支持** EXSLT **” – 2010-08-10 17:20:38

+0

@alejandro:Thnks,你救了我。 :) – 2010-08-10 17:21:47