need to manipulate the tag with xsl

Hi I have the below xml


 <Summary>
      <b>\fs130.This is a summary.</b><br />\fs100. inside this letter.
</Summary>
 
 
Need to update the xml as below
 
  <Summary><body xmlns="http://www.w3.org/1999/xhtml"><p><span style="font-weight:bold;font-size:13pt">This is a summary.</span></p><p><span style="font-weight:normal;font-size:10pt"> inside this letter.</span></p></body></Summary>

Please let me know if this can be done. Thanks in advance.
sri1209Asked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
Interesting use-case, though a bit advanced

I made a solution that almost does it,
but I would suggest to get the normal span to have a two-pass
(or allow the b-span nested inside a plain span)

<?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" version="1.0" encoding="UTF-8" indent="yes"/>
    
    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="text()">
        <xsl:call-template name="process-text"/>
    </xsl:template>

    <xsl:template match="text()" mode="next">
        <xsl:call-template name="process-text"/>
    </xsl:template>
    
    <xsl:template name="process-text">
        <xsl:choose>
            <xsl:when test="starts-with(normalize-space(.), '\fs' )">
                <xsl:value-of select="substring(normalize-space(.), 8) "/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template match="Summary"><!-- put all elements here that require "html" treatment -->
        <xsl:copy-of select="@*"/>
        <xsl:copy>
            <body xmlns="http://www.w3.org/1999/xhtml">
                <xsl:apply-templates select="node()[1]" mode="startpoint"/>
            </body>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="*" mode="startpoint">
        <p xmlns="http://www.w3.org/1999/xhtml">
            <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates select="node()"/>
            </xsl:copy>
            <xsl:apply-templates select="following-sibling::node()[1]" mode="next"/>
        </p>
        <xsl:apply-templates select="following-sibling::br[1]/following-sibling::node()[1]" mode="startpoint"/>
    </xsl:template>
    
    <xsl:template match="text()" mode="startpoint">
        <p xmlns="http://www.w3.org/1999/xhtml">
            <xsl:call-template name="process-text"/>
            <xsl:apply-templates select="following-sibling::node()[1]" mode="next"/>
        </p>
        <xsl:apply-templates select="following-sibling::br[1]/following-sibling::node()[1]" mode="startpoint"/>
    </xsl:template>
    
    
    <xsl:template match="node()" mode="next">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
        <xsl:apply-templates select="following-sibling::node()[1]" mode="next"/>
    </xsl:template>
    
    <xsl:template match="br" mode="next"/>
    
    <xsl:template match="b" mode="next">
        <span style="font-weight:bold;font-size:13pt" xmlns="http://www.w3.org/1999/xhtml">
            <xsl:apply-templates select="node()"/>
        </span>
    </xsl:template>
    
    
</xsl:stylesheet>

Open in new window

0
 
sri1209Author Commented:
Thank you very much, works great.
0
 
Geert BormansInformation ArchitectCommented:
Welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.