循环后XSL放置结束标记

时间:2018-03-29 23:53:03

标签: html xml xslt

我遇到了这个XSL文件的问题,我只能在我的服务器环境中重现,而不能在任何在线测试工具上重现。

XSL:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:output method="xhtml"/>

<xsl:template match="Contest">
    <xsl:choose>
        <xsl:when test="@title = 'MAYOR'">
            <article class="results-cumulative mayor" id="mayoral-candidates">
                <h2>Mayoral Candidates</h2>

                <xsl:for-each select="Candidate">
                    <div class="row candidate-single">
                        <div class="results-cumulative--name columns small-12 large-4">
                            <h3><xsl:value-of select="@name" /></h3>
                        </div>
                        <div class="results-cumulative--votes columns small-12 large-8">
                            <div class="data-bar">
                                <div class="bar"></div>
                            </div>
                        </div>
                    </div>
                </xsl:for-each>
            </article>
        </xsl:when>
        <xsl:otherwise>
            Not Supported
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- do nothing for unmatched text or attribute nodes -->
<xsl:template match="text()|@*"/>

</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Owner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="file:/C:/ELEC.xsd" id="2014">
    <ReportTime>2014-10-14T14:41:03Z</ReportTime>
    <Election id="0" electionName="ELEC1" electionTitle="" final="1" totalBallotsCast="65" totalRegistration="0" totalCastPercentage="00.0" reportedRegistration="0" reportedPercentage="00.0" totalPrecincts="55" precinctsReported="12" precinctsReportedPercentage="21.82">
        <ContestList>
            <Contest id="101" altId2="100001" partyId="1" stateWide="1" title="MAYOR" typeCode="" voteFor="1" runoff="0" ballotsCast="65" castPercentage="00.0" writeinVotes="0" overVotes="0" underVotes="15">
                <Candidate id="1" altId2="1000001" pos="1" name="NAME" partyId="1" winner="1" runoff="0" recount="0">
                </Candidate>
                <Candidate id="2" altId2="1000002" pos="2" name="NAME" partyId="1" winner="1" runoff="0" recount="0">
                </Candidate>
                <Candidate id="3" altId2="1000003" pos="3" name="NAME" partyId="1" winner="1" runoff="0" recount="0">
                </Candidate>
            </Contest>
        </ContestList>
    </Election>
</Owner>

我希望收到的预期输出如下:

<article class="results-cumulative mayor" id="mayoral-candidates">
   <h2>Mayoral Candidates</h2>
   <div class="row candidate-single">
      <div class="results-cumulative--name columns small-12 large-4">
         <h3>NAME</h3>
      </div>
      <div class="results-cumulative--votes columns small-12 large-8">
         <div class="data-bar">
            <div class="bar"></div>
         </div>
      </div>
   </div>
   <div class="row candidate-single">
      <div class="results-cumulative--name columns small-12 large-4">
         <h3>NAME</h3>
      </div>
      <div class="results-cumulative--votes columns small-12 large-8">
         <div class="data-bar">
            <div class="bar"></div>
         </div>
      </div>
   </div>
   <div class="row candidate-single">
      <div class="results-cumulative--name columns small-12 large-4">
         <h3>NAME</h3>
      </div>
      <div class="results-cumulative--votes columns small-12 large-8">
         <div class="data-bar">
            <div class="bar"></div>
         </div>
      </div>
   </div>
</article>

注意,“。do .candidate-single”元素是彼此的兄弟姐妹。相反,我收到了这个:

<article class="results-cumulative mayor" id="mayoral-candidates">
   <h2>Mayoral Candidates</h2>
   <div class="row candidate-single">
      <div class="results-cumulative--name columns small-12 large-4">
         <h3>NAME</h3>
      </div>
      <div class="results-cumulative--votes columns small-12 large-8">
         <div class="data-bar">
            <div class="bar"></div>
         </div>
      </div>
      <div class="row candidate-single">
         <div class="results-cumulative--name columns small-12 large-4">
            <h3>NAME</h3>
         </div>
         <div class="results-cumulative--votes columns small-12 large-8">
            <div class="data-bar">
               <div class="bar"></div>
            </div>
         </div>
         <div class="row candidate-single">
            <div class="results-cumulative--name columns small-12 large-4">
               <h3>NAME</h3>
            </div>
            <div class="results-cumulative--votes columns small-12 large-8">
               <div class="data-bar">
                  <div class="bar"></div>
               </div>
            </div>
         </div>
      </div>
   </div>
</article>

“.row .candidate-single”元素彼此嵌套,我无法弄清楚为什么会发生这种情况。服务器的XSL处理器为系统属性('xsl:vendor')输出“Microsoft”,为系统属性('xsl-version')输出12014-10-14。有什么想法吗?

0 个答案:

没有答案