2010-08-10 246 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