2016-07-05 24 views
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です。私の現在の出力が

<!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

ある

<?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> 

どうすればこの問題を解決できますか?

おかげ

答えて

1

あなたのスタイルシートを宣言:

<xsl:if test="//footnote"> 

はfalseを返します:あなたのXMLで

xpath-default-namespace="http://foo.bar.com/ns" 

footnoteが中したがって、テスト、ノー名前空間にあります。

+0

こんにちは、これは素晴らしいです、あなたはgeniousです:) – user2423959

関連する問題