38692

Question:
This is my xml file:
<HarperCollins>
<BookComingSoon>
<BookDescription>
After a family tragedy...
<NewParagraph/>
Holden Cameron was addicted...
<NewParagraph/>
When equipment, treasure...
</BookDescription>
<BookComingSoon>
</HarperCollins>
and I must change it with XML to look like this(the BookDescription part):
<blurb>
Example text example text example text, woo!
More example text. Amazing!
</blurb>
how do i do this with XSL(1.0)?
this is what i got so far:
<blurb>
<xsl:for-each select="BookDescription">
<xsl:value-of select="."/>
</xsl:for-each>
</blurb>
<strong>EDIT</strong>
this is the full xml doc:
<?xml version="1.0"?>
<HarperCollins>
<BookComingSoon>
<Book>Night Diver</Book>
<By>Elizabeth Lowell</By>
<Pages>368</Pages>
<CoverImage>nd-el.jpg</CoverImage>
<OnSale>4/8/2014</OnSale>
<ForFansOf>Romance</ForFansOf>
<ForFansOf>Suspense</ForFansOf>
<BookDescription>
After a family tragedy...
<NewParagraph/>
Holden Cameron...
<NewParagraph/>
When equipment, treasure...
</BookDescription>
</BookComingSoon>
<BookComingSoon>
<Book>Under a Silent Moon</Book>
<By>Elizabeth Haynes</By>
<Pages>352</Pages>
<CoverImage>uasm-eh.jpg</CoverImage>
<OnSale>4/15/2014</OnSale>
<ForFansOf>Suspense</ForFansOf>
<ForFansOf>Thriller</ForFansOf>
<BookDescription>
In the crisp, ...
<NewParagraph />
As DCI Louisa Smith ...
</BookDescription>
</BookComingSoon>
</HarperCollins>
The for-each I use is to do both the nodes.
Answer1:Could go simpler. You can avoid the empty template by never matching the NewParagraph element in the first place.
<xsl:template match="/">
<blurb><xsl:apply-templates match="//BookDescription/text()" /></blurb>
</xsl:template>
<xsl:template match="BookDescription/text()">
<xsl:value-of select="."/>
</xsl:template>
Answer2:For-each is totally overused :-) Try this:
<xsl:template match="BookComingSoon">
<blurb><xsl:apply-templates match="BookDescription" /></blurb>
</xsl:template>
<xsl:template match="BookDescription/text()">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="NewParagraph" />
The first one will kick the processing of the book description. The second pulls out all the text and surrounds it with
, and the last suppresses the unneeded element.