簡體   English   中英

基本XML / XSLT-許多節點具有相同名稱且由TEXT和其他NODES組成時的值

[英]Basic XML/XSLT - Value-of many nodes when they are have the same name AND When they consists TEXT and other NODES

所以這是我的問題

我試圖用來學習XSL的一些基礎知識的整個簡單XML代碼如下所示:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="penguins.xsl" ?>

<article>
<date>28/06/2000 12:30</date>
<title>Rescued penguins swim home</title>
<para>
    <place>Cape Town</place> 
    Some 150 penguins unaffected by the oil spill began their long swim     from Port Elizabeth
    in the Eastern Cape back to their breeding habitat at Robben Island near Cape Town on Wednesday. </para>

<para>The penguins, who have all been tagged, were transported in a truck hired by the 
    <company>South African National Conservation of Coastal Birds (Sanccob)</company> 
    to Port Elizabeth on Tuesday night. </para>

<para>Its not known how many more birds will be released from Port Elizabeth after receiving treatment. </para>

<para>More than 
    <link ref="www.newsrus.com/oilspill.html">400 tons of fuel oil 
    escaped from the bulk ore carrier Treasure</link> before divers were able to seal the holds. </para>

<para>The ship was carrying 130 000 tons of iron ore and 1 300 tons of fuel oil when she sank off the
     Cape West coast last Friday. </para>

<para>A spokesperson for 
    <company>Sanccob</company>
        , Christina Pretorius said the centre had a capacity to treat 1 000 penguins but presently 
        there were in excess of 4 500 birds being rehabilitated and more would be brought to the 
        centre on Wednesday. </para>
<source>John Rolfe</source>
</article>

我試圖弄清楚,如何使用VALUE-OF打印整個<para>包含其他子子元素,例如<company><link ref=... >以及其余文本。 我被困在這一個:

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

僅打印文本,不打印其他子元素。

對不起這個簡單而基本的問題,但是我剛剛開始使用XML / XSLT

您應該對XSLT使用標准的編碼模式:為每個元素名稱編寫一個模板規則,在其中遞歸處理其子元素:

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

然后,為要執行其他操作的那些元素修改模板規則。

每本XSLT教科書都對此進行了更詳細的介紹,因此,如果您錯過了它,那么在開始編碼之前,您確實應該做更多的閱讀。

聽起來您正在嘗試對param元素執行深層復制。 此答案涵蓋以下XSLT:深層子副本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM