2016-03-12 83 views
0

我有這樣的XML數據文件的格式:我生成的HTML(從XML/XSL)

<?xml-stylesheet type="text/xsl" href="CounselForm.xsl"?> 
<CounselForm Name="A N OTHER"> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>1</Number> 
     <Description>Accurate Reading</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>2</Number> 
     <Description>Words Clearly Spoken</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>3</Number> 
     <Description>Correct Pronunciation</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>4</Number> 
     <Description>Fluent Delivery</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>5</Number> 
     <Description>Appropriate Pausing</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>6</Number> 
     <Description>Proper Sense Stress</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>7</Number> 
     <Description>Principal Ideas Emphasized</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>8</Number> 
     <Description>Suitable Volume</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>9</Number> 
     <Description>Modulation</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>10</Number> 
     <Description>Enthusiasm</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>11</Number> 
     <Description>Warmth And Feeling</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="1" Completed="0"> 
     <Number>12</Number> 
     <Description>Gestures and Facial Expressions</Description> 
     <StartDate>07/03/2016</StartDate> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>13</Number> 
     <Description>Visual Contact</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>14</Number> 
     <Description>Naturalness</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>15</Number> 
     <Description>Good Personal Appearance</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>16</Number> 
     <Description>Poise</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>17</Number> 
     <Description>Use of Microphone</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>18</Number> 
     <Description>Use of Bible in Replying</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>19</Number> 
     <Description>Use of Bible Encouraged</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>20</Number> 
     <Description>Scriptures Effectively Introduced</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>21</Number> 
     <Description>Scriptures Read With Proper Emphasis</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>22</Number> 
     <Description>Scriptures Correctly Applied</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>23</Number> 
     <Description>Practical Value Made Clear</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>24</Number> 
     <Description>Choice of Words</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>25</Number> 
     <Description>Use of an Outline</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>26</Number> 
     <Description>Logical Development of Material</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>27</Number> 
     <Description>Extemporaneous Delivery</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>28</Number> 
     <Description>Conversational Manner</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>29</Number> 
     <Description>Voice Quality</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>30</Number> 
     <Description>Interest Shown in the Other Person</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>31</Number> 
     <Description>Respect Shown to Others</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>32</Number> 
     <Description>Expressed With Conviction</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>33</Number> 
     <Description>Tactful Yet Firm</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>34</Number> 
     <Description>Upbuilding And Positive</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>35</Number> 
     <Description>Repetition for Emphasis</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>36</Number> 
     <Description>Theme Developed</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>37</Number> 
     <Description>Main Points Made to Stand Out</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>38</Number> 
     <Description>Interest - Arousing Introduction</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>39</Number> 
     <Description>Effective Conclusion</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>40</Number> 
     <Description>Accuracy of Statement</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>41</Number> 
     <Description>Understandable to Others</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>42</Number> 
     <Description>Informative to Your Audience</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>43</Number> 
     <Description>Use of Assigned Material</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>44</Number> 
     <Description>Effective Use of Questions</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>45</Number> 
     <Description>Illustrations/Examples That Teach</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>46</Number> 
     <Description>Illustrations From Familiar Situations</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>47</Number> 
     <Description>Effective Use of Visual Aids</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>48</Number> 
     <Description>Reasoning Manner</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>49</Number> 
     <Description>Sound Arguments Given</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>50</Number> 
     <Description>Effort To Reach the Heart</Description> 
    </StudyPoint> 
    <StudyPoint Assigned="0" Completed="0"> 
     <Number>51</Number> 
     <Description>Accurately Timed, Properly Proportioned</Description> 
    </StudyPoint> 
</CounselForm> 

這是當前XSL文件:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" indent="yes" version="4.01" 
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
    doctype-public="//W3C//DTD XHTML 1.0 Transitional//EN"/> 
    <xsl:template match="/"> 
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 
     <head> 
     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
     <title> 
      Counsel Form 
     </title> 
     </head> 
     <body> 
     <h1> 
      Counsel Form for <xsl:value-of select="/CounselForm/@Name"/> 
     </h1> 
     <table> 
      <thead> 
      <tr> 
       <td>Study Point</td> 
       <td>Date Assigned</td> 
       <td>Date Completed</td> 
      </tr> 
      </thead> 
      <tbody> 
      <xsl:apply-templates select="CounselForm/StudyPoint"/> 
      </tbody> 
     </table> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="StudyPoint"> 
    <tr> 
     <td> 
     <xsl:value-of select="Number"/> 
     &#160; 
     <xsl:value-of select="Description"/> 
     </td> 
     <td> 
     <xsl:choose> 
      <xsl:when test="@Assigned=1"> 
      <xsl:value-of select="StartDate"/> 
      </xsl:when> 
      <xsl:otherwise> 
      &#160; 
      </xsl:otherwise> 
     </xsl:choose> 
     </td> 
     <td> 
     <xsl:choose> 
      <xsl:when test="@Completed=1"> 
      <xsl:value-of select="EndDate"/> 
      </xsl:when> 
      <xsl:otherwise> 
      &#160; 
      </xsl:otherwise> 
     </xsl:choose> 
     </td> 
    </tr> 
    </xsl:template> 
</xsl:stylesheet> 

現在,當我看到這個在Internet Explorer中查看源代碼,爲什麼它有太多過多的空格?

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> 
<title> 
      Counsel Form 
     </title> 
</head> 
<body> 
<h1> 
      Counsel Form for A N OTHER</h1> 
<table> 
<thead> 
<tr> 
<td>Study Point</td> 
<td>Date Assigned</td> 
<td>Date Completed</td> 
</tr> 
</thead> 
<tbody> 
<tr xmlns=""> 
<td>1 
       
     Accurate Reading</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>2 
       
     Words Clearly Spoken</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>3 
       
     Correct Pronunciation</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>4 
       
     Fluent Delivery</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>5 
       
     Appropriate Pausing</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>6 
       
     Proper Sense Stress</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>7 
       
     Principal Ideas Emphasized</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>8 
       
     Suitable Volume</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>9 
       
     Modulation</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>10 
       
     Enthusiasm</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>11 
       
     Warmth And Feeling</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>12 
       
     Gestures and Facial Expressions</td> 
<td>07/03/2016</td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>13 
       
     Visual Contact</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>14 
       
     Naturalness</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>15 
       
     Good Personal Appearance</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>16 
       
     Poise</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>17 
       
     Use of Microphone</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>18 
       
     Use of Bible in Replying</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>19 
       
     Use of Bible Encouraged</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>20 
       
     Scriptures Effectively Introduced</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>21 
       
     Scriptures Read With Proper Emphasis</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>22 
       
     Scriptures Correctly Applied</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>23 
       
     Practical Value Made Clear</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>24 
       
     Choice of Words</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>25 
       
     Use of an Outline</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>26 
       
     Logical Development of Material</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>27 
       
     Extemporaneous Delivery</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>28 
       
     Conversational Manner</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>29 
       
     Voice Quality</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>30 
       
     Interest Shown in the Other Person</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>31 
       
     Respect Shown to Others</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>32 
       
     Expressed With Conviction</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>33 
       
     Tactful Yet Firm</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>34 
       
     Upbuilding And Positive</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>35 
       
     Repetition for Emphasis</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>36 
       
     Theme Developed</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>37 
       
     Main Points Made to Stand Out</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>38 
       
     Interest - Arousing Introduction</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>39 
       
     Effective Conclusion</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>40 
       
     Accuracy of Statement</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>41 
       
     Understandable to Others</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>42 
       
     Informative to Your Audience</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>43 
       
     Use of Assigned Material</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>44 
       
     Effective Use of Questions</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>45 
       
     Illustrations/Examples That Teach</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>46 
       
     Illustrations From Familiar Situations</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>47 
       
     Effective Use of Visual Aids</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>48 
       
     Reasoning Manner</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>49 
       
     Sound Arguments Given</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>50 
       
     Effort To Reach the Heart</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
<tr xmlns=""> 
<td>51 
       
     Accurately Timed, Properly Proportioned</td> 
<td> 
        
      </td> 
<td> 
        
      </td> 
</tr> 
</tbody> 
</table> 
</body> 
</html> 

我需要在我的XSL文檔中進行更改以使得生成的HTML看起來更優雅?

謝謝。

安德魯

+0

定義「更優雅」。 XSLT會生成你想要的HTML - 但首先你需要知道你想要什麼。如果你想有樣式,那麼添加一些CSS。按照目前的形式,你的問題不是關於編程。 –

+0

輸出中的所有多餘的空白。 –

+0

比如,結果是'​​2個字清楚地說出'而不是分成3行。 –

回答

1

如果你想在輸出更緊湊的代碼,將內<xsl:text>指示所有文字文本節點 - 例如,更改:

<title> 
    Counsel Form 
</title> 

到:

<title> 
    <xsl:text>Counsel Form</xsl:text> 
</title> 

或移除空格:

<title>Counsel Form</title> 

無關你的問題,但你有一個命名空間的問題:你的錶行和他們的後代都沒有命名空間,而表和它的祖先是在XHTML命名空間:你應該申報的XHTML命名空間樣式表級別的默認名稱空間。

+0

命名空間問題:你的意思是** **?這是由IE完成的,因爲除了開始之外,我沒有指定任何東西。換句話說,我不確定你的意思。 –

+0

另外,如何將該xsl:文本與代碼進一步向下顯示在學習點和說明中? –

+1

「*你的意思是?*」是的。這不是IE完成的,它是由你的樣式表完成的。您應該將'xmlns =「http://www.w3.org/1999/xhtml」'添加到'xsl:stylesheet'元素中。 –