Page 1 of 1

Change HTML tags to string

Posted: Wed Mar 14, 2012 3:36 pm
by Marzipan
<html xmlns="http://www.w3.org/1999/xhtml" xml:space="preserve"><div><font color="#ff0000">CRITICAL CARE:</font> Audit central line insertion checklists for completion: twice weekly for each patient present in the unit with a CL for a total of 4 weeks. </div></html>

in a XML document and change it to string? Encapsulate it in single quotes?

an example would be appreciated.

Re: Change HTML tags to string

Posted: Wed Mar 14, 2012 4:22 pm
by adrian
Hello,
Marzipan wrote:an example would be appreciated.
I was about to ask for the same thing.

What do you want to obtain in the output, can you offer an example?
You want the result of the XSLT transformation to be the concatenated text of the HTML(without the tags) between single quotes?

Regards,
Adrian

Re: Change HTML tags to string

Posted: Wed Mar 14, 2012 5:05 pm
by Marzipan
No I want the entire HTML tag as the value. Not sure if I should append single or escaped quotes? How to encapsulate?

Re: Change HTML tags to string

Posted: Wed Mar 14, 2012 5:37 pm
by adrian
You have to escape all the XML special characters: <, >, &, ", '
Oxygen already provides such a function. Select the text in the editor, right click on it and from the popup menu choose: Source > Escape Selection. Press OK in the Escape Characters dialog and the selected text will be escaped.
e.g.

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml" xml:space="preserve"><div><font color="#ff0000">CRITICAL CARE:</font> Audit central line insertion checklists for completion: twice weekly for each patient present in the unit with a CL for a total of 4 weeks. </div></html>
Quotes are only necessary if you want to use this as an attribute value.
e.g. <a attr="val">

Regards,
Adrian

Re: Change HTML tags to string

Posted: Wed Mar 14, 2012 6:01 pm
by Marzipan
Is there a way to do this in a xslt only for all <html></html>

Re: Change HTML tags to string

Posted: Fri Mar 16, 2012 4:42 pm
by Marzipan
Found this and added to .xsl; not sure how to call it?

<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, '<')">
<xsl:value-of select="substring-before($html, '<')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>

<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>


<!-- Removes levels with out data, easier to flatten and process in SSIS-->

<xsl:template match="*[contains(name(), 'Group')]">
<xsl:apply-templates/>
</xsl:template>


<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, '<')">
<xsl:value-of select="substring-before($html, '<')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>