Reputation: 5
I have an xml stylesheet that takes multiple xml documents and converts and combines them. However all the xml documents contain the same detail, the node names are different. In the one that gives me problems, I have a:
<description>
some text...
<NewLine/>
some text...
<NewLine/>
some text...
</description>
How can I change this to:
<details>
<p>some text...</p>
<p>some text...</p>
<p>some text...</p>
</details>
Upvotes: 0
Views: 195
Reputation: 23627
Using this XSLT you will obtain the result you expect, for the source XML that you provided:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="description">
<details>
<xsl:apply-templates />
</details>
</xsl:template>
<xsl:template match="description/text()">
<p><xsl:value-of select="normalize-space(.)"/></p>
</xsl:template>
</xsl:stylesheet>
If your source is actually more complex, then you will have to adjust the stylesheet to deal with that. I'm assuming that <NewLine/>
is actually a tag (and not a representation of the newline character, and that it is always empty).
Upvotes: 2