2014-01-10 39 views
0

外部參照標籤我使用這個XML如何解析在XSLT

<body> 
<p>The results are used to optimize the design in the next product cycle through the V.</p> 
<p> This feedback is represented by arrows between the left and right side of the V<xref ref-type="fig" rid="F1">Figure 1</xref>Physical test benches are often comprised of customized static.</p> 
</body> 

,並以此作爲XSLT

<xsl:for-each select="body/"> 
<xsl:value-of select="text()"> 
</xsl:for-each> 

而且它給輸出

結果被用來通過V優化下一個產品週期的設計。該反饋由V的左側和右側之間的箭頭表示。

它不讀取外部參照標記後的字符串。但我想解析它,並希望以下輸出。

的結果用於進行優化設計中通過V.This反饋下一個產品循環由V.物理測試臺的左側和右側之間的箭頭表示通常由定製靜態的。

我應該對Xslt做些什麼改變,以便它也可以傳遞這個標籤?

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/> 

    <xsl:template match="book-part"> 
    <html> 
     <head></head> 
     <body> 
     <xsl:for-each select="book-meta"> 
      <p> 
      <b> 
       <xsl:value-of select="book-title-group/book-title"/> 
      </b> 
      </p> 
     </xsl:for-each> 


     <xsl:for-each select="book-part-meta"> 
      <p> 
      <b> 
       <xsl:value-of select="title-group/title"/> 
      </b> 
      </p> 

     </xsl:for-each> 

     <xsl:for-each select="body/sec/p"> 
      <xsl:value-of select="text()"/> 
     </xsl:for-each> 

     </body> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 

這是我的xml。

<?xml version="1.0" encoding="utf-8"?> 
<book-part book-part-type="chapter" book-part-number="1" id="PT-161_ch_1"> 
<book-meta> 
<book-title-group> 
<book-title>Software&#x002d;Hardware Integration in Automotive Product Development</book-title> 
</book-title-group> 
</book-meta> 
<body> 
<sec id="ch1.1"> 
<title>INTRODUCTION</title> 
<p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market. New system architectures are providing the performance and memory capability necessary to keep up with the hardware performance and software growth required by the automotive market trends. All of this technology growth implies a higher product cost and increased engineering effort required to develop these new products.</p> 
<p>IVV is that portion of the complete product or system life&#x002d;cycle phase captured in the right&#x002d;hand side &#x0028;RHS&#x0029; of the V&#x002d;diagram model &#x0028;see <xref ref-type="fig" rid="F96">Fig. 1</xref>&#x0029;. This RHS portion is sometimes called the &#x201C;build, test, and deliver phase &#x005B;<xref ref-type="bibr" rid="R65">1</xref>&#x005D;.&#x201D; The model&#x2019;s left&#x002d;hand side is where the architectural design is functionally partitioned and decomposed into manageable subsystems and components. At the lowest levels of decomposition&#x002d;i.e., the bottom of the &#x201C;V&#x201D;&#x002d;the resulting subsystems are ready to be recomposed into an integrated whole. This integration phase is where verification, validation, and test of all the hardware and software occur.</p> 

</sec> 
</body> 
</book-part> 

回答

0

寫另一個模板來捕捉xref元素的內容:

<xsl:template match="xref"> 
    <xsl:value-of select="."/> 
</xsl:template> 

話雖如此,這取決於你節目樣式表的各個方面。這是一個完整的樣式表也xref內輸出文本:

<?xml version="1.0" encoding="utf-8"?> 

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="xml" indent="yes"/> 

<xsl:template match="/body"> 
    <xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="p|xref"> 
    <xsl:value-of select="."/> 
</xsl:template> 

</xsl:stylesheet> 

您應該避免使用xsl:for-each在可能的情況。使用多個模板和apply-templates是XSLT更加靈活的方式。

編輯:我補充說,更新後的輸入工作,類似於你試圖解決的XSLT樣式表。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="/book-part"> 
    <html> 
    <head></head> 
    <body> 
     <xsl:apply-templates/> 
    </body> 
    </html> 
</xsl:template> 

<xsl:template match="book-meta"> 
<p> 
    <b> 
     <xsl:value-of select="book-title-group/book-title"/> 
    </b> 
</p> 
</xsl:template> 

<xsl:template match="body|sec|p"> 
<xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="text()[parent::p]"> 
<xsl:value-of select="."/> 
</xsl:template> 

<xsl:template match="text()[parent::xref]"/> 

</xsl:stylesheet> 

適用於以下輸入:

<?xml version="1.0" encoding="utf-8"?> 
<book-part book-part-type="chapter" book-part-number="1" id="PT-161_ch_1"> 
<book-meta> 
    <book-title-group> 
    <book-title>Software and Hardware Integration in Automotive Product Development</book-title> 
    </book-title-group> 
</book-meta> 
<body> 
    <sec id="ch1.1"> 
    <title>INTRODUCTION</title> 
    <p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market.</p> 
    <p> First part of the sentence <xref ref-type="fig" rid="F96">Fig. 1</xref>second part of the sentence.</p> 
    </sec> 
</body> 
</book-part> 

會得到以下的輸出:

<!DOCTYPE html 
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
</head> 
<body> 
    <p><b>Software and Hardware Integration in Automotive Product Development</b></p>INTRODUCTIONThe trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the 
    automotive electronics market. First part of the sentence second part of the sentence. 
</body> 
</html> 
+0

我沒有得到地方寫。因爲不能是的子項,並且如果我創建另一個模板,那麼它會再次提供舊的結果。它不解析標記。 – user

+0

沒錯。可以使用我建議的樣式表,也可以通過編輯將整個樣式表添加到帖子中。只有這樣我才能告訴你準確的做法。 –

+0

我已添加我的xslt。現在請解釋我在哪裏編輯,以解析標記。 – user