Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 未正确调用值_Xml_Xslt - Fatal编程技术网

Xml 未正确调用值

Xml 未正确调用值,xml,xslt,Xml,Xslt,我有下面的XML <?xml version="1.0" encoding="UTF-8"?> <chapter> <toc> <toc-part> <toc-div> <toc-item> <toc-title>8.1 Introduction

我有下面的XML

 <?xml version="1.0" encoding="UTF-8"?>
    <chapter>
        <toc>
            <toc-part>
                <toc-div>
                    <toc-item>
                        <toc-title>8.1 Introduction</toc-title>
                        <toc-pg>749</toc-pg>
                        <toc-subitem level="1">
                            <toc-title>Importance and vitality of contracts</toc-title>
                            <toc-pg>750</toc-pg>
                        </toc-subitem>
                    </toc-item>
                    <toc-item>
                        <toc-title>8.2 The Electronic Transactions Act</toc-title>
                        <toc-pg>751</toc-pg>
                        <toc-subitem level="1">
                            <toc-title>Introduction</toc-title>
                            <toc-pg>751</toc-pg>
                        </toc-subitem>
                    </toc-item>
                </toc-div>
            </toc-part>
        </toc>

        <page num="747"/>
        <section level="sect1">
            <title><content-style font-style="bold">8.1 INTRODUCTION</content-style></title>
            <para num="8.1.1">One definition of information technology (&#8216;IT&#8217;) </para>
            <para num="8.1.2">Without doubt,</para>
            <section level="sect2">
                <title><content-style font-style="bold">Importance and vitality of contracts</content-style></title>
                <para num="8.1.7">Contracts are of fundamental importance to IT transactions. As the Court of Appeal noted in </para>
                <para num="8.1.8">The case is also</para>
            </section>
        </section>
        <section level="sect1">
            <title><content-style font-style="bold">8.2 THE ELECTRONIC TRANSACTIONS ACT</content-style></title>
            <section level="sect2">
                <title><content-style font-style="bold">Introduction</content-style></title>
                <para num="8.2.1">TheThere are key provisions on electronic contracts, electronic and digital signatures and electronic records.</para>
            </section>
    <section level="sect2">
<title><content-style font-style="bold">Purpose and construction</content-style></title>
<para num="8.2.5">The ETA has an uncommon feature among the body of</para>
</section>
        </section>
    </chapter>
预期输出如下所示

<table class="toc-item-first-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">8.1 Introduction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-1-7">749</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Importance and vitality of contracts</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-1-7">750</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-first-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">8.2 The Electronic Transactions Act</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-2-1">751</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Introduction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-2-1">751</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Purpose and construction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_9/P8-2-5">752</a>
            </td>
        </tr>
    </tbody>
</table> 

8.1导言
合同的重要性和生命力
8.2《电子交易法》
介绍
目的和结构
toc子项
中,我得到的值为
,请告诉我哪里出错了


谢谢

我添加了样式表中缺少的以下块(没有它,您的输出不一样):

并将它们粘贴到
toc子项
模板中的变量定义上,该模板不选择任何内容

我建议您花一些时间重构样式表。您将更好地理解它是如何工作的,它将变得更简单,更不容易出错,并且可能只有其原始大小的1/4或更小。从删除重复和不必要的变量开始

更新

这些是我在您发布的XSLT文件中所做的唯一更改,以使其正常工作(从
toc项
模板中复制了
$toc title
$refe
定义):

。。。
...
...
...
...

你能添加一段代码来显示你的预期输出吗?嗨@helderdarocha,很抱歉延迟回复,我已经用预期输出更新了我的问题。感谢您的XSLT样式表有大量代码重复,这使它变得不必要的复杂。你在很多地方做着相同的事情。也许如果您重构它并尝试减少代码重复,您可能会发现错误。我注意到代码引用了样式表中应该存在的某个
元素。您可以忽略
ntw
它只是一个名称空间,您可以注释掉它,我还使用
ntw
数据更新了XSLT。它应该是。至少它在您粘贴到此处的示例中有效。我刚刚替换了这些值,得到了您的输出。可能您的实际样式表还有其他问题。尝试复制您在此处发布的代码,并尝试对其进行转换。
<table class="toc-item-first-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">8.1 Introduction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-1-7">749</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Importance and vitality of contracts</td>
            <td class="toc-pg">
                <a href="LRSC_CH_0/P">750</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-first-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">8.2 The Electronic Transactions Act</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-2-1">751</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Introduction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_0/P">751</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Purpose and construction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_0/P">752</a>
            </td>
        </tr>
    </tbody>
</table>  
<table class="toc-item-first-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">8.1 Introduction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-1-7">749</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Importance and vitality of contracts</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-1-7">750</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-first-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">8.2 The Electronic Transactions Act</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-2-1">751</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Introduction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_8/P8-2-1">751</a>
            </td>
        </tr>
    </tbody>
</table>
<table class="toc-item-second-level">
    <tbody>
        <tr>
            <td class="toc-item-num"></td>
            <td class="toc-title">Purpose and construction</td>
            <td class="toc-pg">
                <a href="LRSC_CH_9/P8-2-5">752</a>
            </td>
        </tr>
    </tbody>
</table> 
<ntw:words>
    <ntw:nums num="1" word="first" />
    <ntw:nums num="2" word="second" />
</ntw:words>
<xsl:variable name="toc-title" select="current()/toc-title/*" />
<xsl:variable name="refe">...</xsl:variable>
<xsl:stylesheet ...> ...
   <xsl:template match="toc-subitem">
     ...
     <xsl:variable name="toc-title" select="upper-case(current()/toc-title/text())" />
     ...
     <xsl:variable name="refe">
       <xsl:choose>
        <xsl:when test="//section[title/*[upper-case(text()) = $toc-title]]/section[1]/para[1]/@num">
         <xsl:value-of select="//section[title/*[upper-case(text()) = $toc-title]]/section[1]/para[1]/@num[1]"/>
        </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="//section[title/*[upper-case(text()) = $toc-title]]/para[1]/@num[1]"/>   
        </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
    ...
  ...