XSL 处理器堆栈已溢出 - 无法理解为什么

发布于 2024-09-13 08:22:32 字数 5465 浏览 4 评论 0原文

我正在尝试有条件地显示 HTML 页面的内容,具体取决于是否为公认的公司生成文档。

但是,转换不起作用,我不明白为什么:(我使用 MSXML3.0 作为转换器,使用 oXygen 作为 IDE,这给出了我在下面提出的错误。

我所做的是构造一长串所有认可的公司(默认和额外的,如果有的话)。然后,我将它们分成存储在 $companiesKnownList 变量中的 元素,以确定公司是否在该列表中。我计算它出现的次数:

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

如果它小于 1,则该公司不会出现在 $companiesKnownList 变量中,因此不会被识别;否则,如果它出现在 $ 中。 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=如果我有一家无法识别的公司,例如 @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 是公认的公司,但转换失败。

在此示例中,bla 不是公认的公司,转换成功并显示文本:“此文档未识别此类型的公司”。

I'm trying to conditionally display the content of HTML page depending if a document being generated for a recognised company or not.

However, the transformation doesn't work and I can't understand why :( I use MSXML3.0 as transformer and oXygen as IDE, which gives the errors I presented below.

What I do is to construct a long string of all recognised companies (default and extra if any). I then split them into <token> elements that are stored in the $companiesKnownList variable. To determine if a company is in that list I count how many times it occurs:

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

If it's less than 1, then the company doesn't appear in the $companiesKnownList variable and therefore is not recognized. Otherwise, if it appears in the $companiesKnownList variable once or more times it is a recognized company. Nevertheless, this is where it breaks and displays the following error:

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

I've noticed that if my XML has got a recognised company, ex @ProductName="ski" then transformation fails with stack overflow. If I have an unrecognized company, ex @ProductName="bla" the transformation works and text that it isn't a recognized company is displayed.

I don't understand what's going wrong with valid companies. I would be more than grateful if you could help me out. I have been staring at it for a day now...without any progress :S

Thanks!

Here is my stylesheet:

<?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]) < 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 is something simple like:

In this example, ski is recognized company, but transformation fails.
<?xml version="1.0" encoding="UTF-8"?>
<Doc ProductName="ski" />

In this example, bla is not a recognized company and transformation succeeds with displaying text: "This type of company is NOT recognised for this document."
<?xml version="1.0" encoding="UTF-8"?>
<Doc ProductName="bla" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听风念你 2024-09-20 08:22:32

您需要添加命名模板 str:tokenize 的实现。检查 Jeni Tennison 的实现 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>

You need to add the implementation of your named template str:tokenize. Check Jeni Tennison implementation at http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl

Then, add this as stylesheet top element, with correct href:

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

With that changes (and closing your last template) with this input:

<Doc ProductName="ski" />

Ouput:

<!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>
仙女 2024-09-20 08:22:32

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

请您更正这个问题,以便只提供真实的信息吗?

MSXML (any version) does not support EXSLT -- and the XSLT processor produces an error message.

Could you, please, correct the question so that only true information is present?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文