najmaka
najmaka

Reputation: 1

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

So here's my question

The whole simple XML code that i'm trying to deal with to learn some basics of XSL is presented like this:

<?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>

I'm trying to figure out, how to use VALUE-OF to print whole <para> consists of other subchilds for e.g <company> or <link ref=...> and with rest of the text. I'm stuck with this one:

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

which prints only text, without any other subchilds.

Sorry for that simple and basic question, but i'v just started XML/XSLT

Upvotes: 0

Views: 48

Answers (2)

Michael Kay
Michael Kay

Reputation: 163262

You should be using the standard coding pattern for XSLT: write a template rule for each element name, in which you recurse to process its children:

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

Then modify the template rules for those elements where you want to do something different.

This is covered in much more detail in every XSLT textbook, so if you missed it then you really should be doing more reading before you start coding.

Upvotes: 1

Sprotty
Sprotty

Reputation: 5973

It sounds like you are trying to perform a deep copy on the param element. This answer covers this XSLT: deep child copy

Upvotes: 0

Related Questions