I'm stuck on what I think should be simple. I searched around but couldn't find a solution. I hope you help me.
I have an XML element with an attribute that contains escaped HTML elements:
<Booking>
<BookingComments Type="RAM" comment="RAM name fred<br/>Tel 09876554<br/>Email fred@bla.com" />
</Booking>
What I need to get is to parse the HTML elements and content from the @comment attribute to be the content of the element
in the following way:
<p>
RAM name fred<br/>Tel 09876554<br/>Email fred@bla.com
<p>
Here is my XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn" version="1.0">
<xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
doctype-system="http://www.w3.org/TR/html4/loose.dtd" encoding="UTF-8" indent="yes" />
<xsl:template name="some-template">
<p>Some text</p>
<p>
<xsl:copy-of
select="/Booking/BookingComments[lower-case(@Type)='ram'][1]/@comment"/>
</p>
</xsl:template>
</xsl:stylesheet>
I read that copy is a good way to restore escaped HTML elements back to their respective elements. In this particular case, since the attribute is first copied, it will also convert it to an attribute. Therefore, I get:
<p comment="RAM name fred<br/>Tel 09876554<br/>Email fred@bla.com"></p>
This is not what I want.
If I use apply patterns instead of patterns, as in:
p- , HTML-.
<p>RAM name fred<br/>Tel 09876554<br/>Email fred@bla.com</p>
, - . !
.