Reputation: 77
i want to fetch normal text from xml which one field containing html data.i cant put condition on template.pls suggest me any solution.
<?xml version="1.0" encoding="UTF-8"?>
<workdetail>
<field name="summaryText1"><UL style="MARGIN-TOP: 0in" type=disc>
<LI style="TEXT-ALIGN: justify;MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="mso-fareast-font-family: 'timesnewroman'; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-style: italic"><FONT size=2>Manage the daily activities of the HOD s office.<?xml:namespace prefix = o /><o:p></o:p></FONT></SPAN></LI>
<LI style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="mso-fareast-font-family: 'timesnewroman'; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-style: italic"><FONT size=2>Handle and manage all communication, correspondence and filing of documents. <o:p></o:p></FONT></SPAN></LI>
<LI style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="mso-fareast-font-family: 'timesnewroman'; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-style: italic"><FONT size=2>Fix appointments, arrange for meetings, conferences etc.<o:p></o:p></FONT></SPAN></LI>
</workdetail>
mu xsl file is as
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<workdetail>
<xsl:apply-templates select="*" />
</workdetail>
</xsl:template>
<xsl:template match="*:workdetail">
<xsl:variable name="text" select="*:field[starts-with(@name,'summaryText1')]"/>
<xsl:choose>
<xsl:when test="contains($text, '<')">
<xsl:value-of select="substring-after($text, '<')"/>
<xsl:variable name="text" select="substring-after($text, '>')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:stylesheet>
this is returning everything after > tag. can i pass more value in this which will return only text document.
Upvotes: 1
Views: 5010
Reputation: 167716
With Saxon 9.5 PE you should be able to use http://www.saxonica.com/documentation/index.html#!functions/saxon/parse-html:
<xsl:template match="workdetail/field[@name = 'summaryText1']">
<xsl:value-of select="saxon:parse-html(.)"/>
</xsl:template>
where you have
<xsl:stylesheet xmlns:saxon="http://saxon.sf.net/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">...</xsl:stylesheet>
declared on the root element of your stylesheet.
If you don't have access to a HTML parser you could try to strip markup with a replace
and a regular expression but the following is made as a suggestion on how to approach that, the regular expression is not tested thoroughly:
<xsl:template match="workdetail/field[@name = 'summaryText1']">
<xsl:value-of select="replace(., '</?\w+[^<]*>', '')"/>
</xsl:template>
Upvotes: 4