2016-01-21 57 views
-1

輸入帶上H3位於p -使用XSLT

<data> 
     <container> 
     <strong>Code Development</strong> 
     <br/> 
     here to support 
     <ul class="nested"> 
      <li>list 1</li> 
      <li>list 2</li> 
      <li>list 3</li> 
      <li>list 4</li> 
     </ul> 
something here 
<strong>this is strong</strong> 
     </container> 
    </data> 

預期輸出 -

  <h3>Code Development</h3> 
     <p> 
     here to support 
     <ul class="nested"> 
      <li>list 1</li> 
      <li>list 2</li> 
      <li>list 3</li> 
      <li>list 4</li> 
     </ul> 
     </p> 

<h3>this is strong</h3> 
<p> something here</p> 

強標籤應成爲H3和自H3不能內部<p>這樣移動它外面數p作爲第一個在第p頁之前出現。

+2

凡到底在堅持呢? –

+0

邁克爾 - 我想處理p標籤外的h3以及p中的其他所有內容。不知道,如何避免只是h3 – Stark

+0

恐怕你錯過了我的觀點。如果您有特定的困難,請指出 - 最好是發佈您嘗試過的內容。否則,它看起來像你想讓某人爲你做你的工作。 –

回答

0

試試這個:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <xsl:apply-templates/> 
    </xsl:template> 

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

    <xsl:template match="container/text()"> 
     <xsl:if test="string-length(normalize-space()) > 0"> 
      <p><xsl:value-of select="."/></p> 
     </xsl:if> 
    </xsl:template> 

    <xsl:template match="ul"> 
     <xsl:copy-of select="."/> 
    </xsl:template> 

</xsl:stylesheet> 

這裏是一個實際的例子:http://www.utilities-online.info/xsltransformation/?save=5c53ab7f-0a1e-4fba-a608-4bb2d6ec1de0-xsltransformation#.VqDQ1SArK90

+0

感謝這個艾哈邁德。其實,我需要把除了強標籤以外的所有東西放在p標籤內。所以,ul應該進入p。只是我需要避免像h3那樣強大,並且在p標籤要構建時將它放在外面。 – Stark