无法理解为什么虽然声明

时间:2016-07-05 08:26:22

标签: xslt xslt-2.0

我正在编写一个XSLT脚本,并且有一个名为footnotes的部分,我的脚本正在捕获除脚注之外的所有元素。我正在使用XSL2.0,而下面是我的XML

<?xml version="1.0" encoding="utf-8"?>
<chapter num="D" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:acknowledgement="file://acknowledgement.xsd" xmlns:admission="file://admission.xsd" xmlns:affidavit="file://affidavit.xsd" xmlns:agreement="file://agreement.xsd" xmlns:appeal="file://appeal.xsd" xmlns:appearance="file://appearance.xsd" xmlns:application="file://application.xsd" xmlns:assent="file://assent.xsd" xmlns:authorisation="file://authorisation.xsd" xmlns:award="file://award.xsd" xmlns:brief="file://brief.xsd" xmlns:caveat="file://caveat.xsd" xmlns:certificate="file://certificate.xsd" xmlns:checklist="file://checklist.xsd" xmlns:claim="file://claim.xsd" xmlns:clause="file://clause.xsd" xmlns:comparisontable="file://comparisontable.xsd" xmlns:conditionsofcontract="file://conditionsofcontract.xsd" xmlns:declaration="file://declaration.xsd" xmlns:defaultjudgment="file://defaultjudgment.xsd" xmlns:defence="file://defence.xsd" xmlns:demand="file://demand.xsd" xmlns:flowchart="file://flowchart.xsd" xmlns:form="file://form.xsd" xmlns:guarantee="file://guarantee.xsd" xmlns:instruction="file://instruction.xsd" xmlns:judgment="file://judgment.xsd" xmlns:letter="file://letter.xsd" xmlns:minutes="file://minutes.xsd" xmlns:notice="file://notice.xsd" xmlns:oath="file://oath.xsd" xmlns:order="file://order.xsd" xmlns:patent="file://patent.xsd" xmlns:petition="file://petition.xsd" xmlns:powerofattorney="file://powerofattorney.xsd" xmlns:praecipe="file://praecipe.xsd" xmlns:questionnaire="file://questionnaire.xsd" xmlns:recognisance="file://recognisance.xsd" xmlns:release="file://release.xsd" xmlns:renunciation="file://renunciation.xsd" xmlns:reply="file://reply.xsd" xmlns:report="file://report.xsd" xmlns:request="file://request.xsd" xmlns:schedule="file://schedule.xsd" xmlns:statementofclaim="file://statementofclaim.xsd" xmlns:subpoena="file://subpoena.xsd" xmlns:summons="file://summons.xsd" xmlns:undertaking="file://undertaking.xsd" xmlns:warrant="file://warrant.xsd" xmlns:writ="file://writ.xsd" xmlns:book="file://book.xsd" xmlns:forms="file://forms.xsd" xmlns:misc="file://misc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:htm="http://www.w3.org/TR/html5/">
          <htm:p align="center">
            <htm:b>Bold Content</htm:b>
            <footnote num="1">
              <para>
                Footnote content.
              </para>
            </footnote>
          </htm:p>
        </chapter>

以下是我的XSLT。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" xmlns:altova="http://www.altova.com/xslt-extensions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:acknowledgement="file://acknowledgement.xsd" xmlns:admission="file://admission.xsd" xmlns:affidavit="file://affidavit.xsd" xmlns:agreement="file://agreement.xsd" xmlns:appeal="file://appeal.xsd" xmlns:appearance="file://appearance.xsd" xmlns:application="file://application.xsd" xmlns:assent="file://assent.xsd" xmlns:authorisation="file://authorisation.xsd" xmlns:award="file://award.xsd" xmlns:brief="file://brief.xsd" xmlns:caveat="file://caveat.xsd" xmlns:certificate="file://certificate.xsd" xmlns:checklist="file://checklist.xsd" xmlns:claim="file://claim.xsd" xmlns:clause="file://clause.xsd" xmlns:comparisontable="file://comparisontable.xsd" xmlns:conditionsofcontract="file://conditionsofcontract.xsd" xmlns:declaration="file://declaration.xsd" xmlns:defaultjudgment="file://defaultjudgment.xsd" xmlns:defence="file://defence.xsd" xmlns:demand="file://demand.xsd" xmlns:flowchart="file://flowchart.xsd" xmlns:form="file://form.xsd" xmlns:guarantee="file://guarantee.xsd" xmlns:instruction="file://instruction.xsd" xmlns:judgment="file://judgment.xsd" xmlns:letter="file://letter.xsd" xmlns:minutes="file://minutes.xsd" xmlns:notice="file://notice.xsd" xmlns:oath="file://oath.xsd" xmlns:order="file://order.xsd" xmlns:patent="file://patent.xsd" xmlns:petition="file://petition.xsd" xmlns:powerofattorney="file://powerofattorney.xsd" xmlns:praecipe="file://praecipe.xsd" xmlns:questionnaire="file://questionnaire.xsd" xmlns:recognisance="file://recognisance.xsd" xmlns:release="file://release.xsd" xmlns:renunciation="file://renunciation.xsd" xmlns:reply="file://reply.xsd" xmlns:report="file://report.xsd" xmlns:request="file://request.xsd" xmlns:schedule="file://schedule.xsd" xmlns:statementofclaim="file://statementofclaim.xsd" xmlns:subpoena="file://subpoena.xsd" xmlns:summons="file://summons.xsd" xmlns:undertaking="file://undertaking.xsd" xmlns:warrant="file://warrant.xsd" xmlns:writ="file://writ.xsd" xmlns:book="file://book.xsd" xmlns:forms="file://forms.xsd" xmlns:misc="file://misc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:htm="http://www.w3.org/TR/html5/" xpath-default-namespace="http://foo.bar.com/ns" exclude-result-prefixes="#all">
    <xsl:output method="html"/>
    <xsl:strip-space elements="*"/>
    <!--<xsl:preserve-space elements="para"/>-->
    <xsl:variable name="nums" as="element()+">
        <ntw:nums num="1" word="first"/>
        <ntw:nums num="2" word="second"/>
        <ntw:nums num="3" word="third"/>
        <ntw:nums num="4" word="forth"/>
        <ntw:nums num="5" word="fifth"/>
        <ntw:nums num="6" word="sixth"/>
        <ntw:nums num="7" word="seventh"/>
        <ntw:nums num="8" word="eighth"/>
        <ntw:nums num="9" word="nighth"/>
        <ntw:nums num="10" word="tenth"/>
    </xsl:variable>
    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html>]]></xsl:text>
        <html>
            <head>
                <xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
                <title>
                    <xsl:value-of select="chapter/title/text()"/>
                </title>
                <link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"/>
                <xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
            </head>
            <body>      
            <section class="tr_chapter">
                <xsl:apply-templates/>
                </section>
                <xsl:if test="//footnote"> 
                    <section class="tr_footnotes">
                        <xsl:text disable-output-escaping="yes"><![CDATA[<hr />]]></xsl:text>
                        <xsl:apply-templates select="//page | //footnote" mode="footnote"/>
                    </section>
                </xsl:if>
            </body>
        </html>
    </xsl:template>



    <xsl:template match="chapter">
        <xsl:apply-templates select="descendant::title[1]/page" mode="first"/>
        <div class="chapter">
            <xsl:variable name="num_S">
                <xsl:value-of select="."/>
            </xsl:variable>
            <a name="CLIHK_CH_{$num_S}"/>
            <div class="chapter-title">
                <span class="chapter-num">
                    <xsl:value-of select="normalize-space(concat('Chapter ',format-number(./@num,'0')))"/>
                </span>
                <xsl:text disable-output-escaping="yes"><![CDATA[<br /><br />]]></xsl:text>
                <xsl:apply-templates select="title/node() except descendant-or-self::page"/>
                <xsl:text disable-output-escaping="yes"><![CDATA[<br /><br />]]></xsl:text>
                <xsl:apply-templates select="chapter-meta"/>
            </div>
            <xsl:apply-templates select="child::node()[not(self::title|self::chapter-meta)]"/>
        </div>
    </xsl:template>

    <xsl:template match="htm:b">
        <span class="font-style-bold">
            <xsl:apply-templates/>
        </span>
    </xsl:template>

    <xsl:template match="htm:p">
        <xsl:apply-templates select="./node()[1][self::page]" mode="first"/>
        <div>
            <xsl:choose>
                <xsl:when test="./@align">
                    <xsl:attribute name="class"><xsl:text>para align-</xsl:text><xsl:value-of select="./@align"/></xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="class"><xsl:text>para</xsl:text></xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/>
        </div>
    </xsl:template>


    <xsl:template match="footnote">
        <xsl:variable name="cnt" select="count(preceding::footnote)+1"/>
        <xsl:variable name="varHeaderNote" select='concat("f",$cnt)'/>
        <xsl:variable name="varFootNote" select='concat("#ftn.",$cnt)'/>
        <sup>
            <a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn">
                <xsl:value-of select="@num"/>
            </a>
        </sup>
    </xsl:template>


    <xsl:template match="footnote" mode="footnote">
        <xsl:variable name="cnt" select="count(preceding::footnote)+1"/>
        <div class="tr_footnote">
            <div class="footnote">
                <sup>
                    <a>
                        <xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:value-of select="$cnt"/></xsl:attribute>
                        <xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:value-of select="$cnt"/></xsl:attribute>
                        <xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
                        <xsl:value-of select="@num"/>
                    </a>
                </sup>
                <xsl:apply-templates/>
            </div>
        </div>
    </xsl:template>
</xsl:stylesheet>

我目前的输出如下

<!DOCTYPE html><html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
      <title></title>
      <link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"></link>
   </head>
   <body>
      <section class="tr_chapter">
         <div class="para align-center"><span class="font-style-bold">Bold Content</span>
            Footnote content.

         </div>
      </section>
   </body>
</html>

但是我的预期输出是

<!DOCTYPE html><html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
      <title></title>
      <link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"></link>
   </head>
   <body>
      <section class="tr_chapter">
         <div class="para align-center"><span class="font-style-bold">Bold Content</span><sup>
                            <a name="f1" href="#ftn.1" class="tr_ftn">1</a>
                        </sup>

         </div>
      </section>

<section class="tr_footnotes"><hr/>
<div class="tr_footnote">
                <div class="footnote">
                    <sup>
                        <a name="ftn.1" href="#f1" class="tr_ftn">1</a>
                    </sup>
                    <div class="para">Footnote content.
        </div>
                </div>
            </div></section>

   </body>
</html>

这是一个有效的demo

请让我知道我哪里出错了,我该如何解决这个问题。

由于

1 个答案:

答案 0 :(得分:1)

您的样式表声明:

$booking_temp_variable

XML中的xpath-default-namespace="http://foo.bar.com/ns" 没有名称空间,因此测试位于:

footnote

返回false。

相关问题