繁体   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