Skip to main content
improved formatting and added tag
Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

I have a requirement that I need to handle B  (Bold), I  (Italic) and U  (underline) tagtags. We are using XSLT and XPath. I

I have an RTF field named <text>......</text>. I.

I entered some text in this RTF field and made it as boldBold and Italic The, the source xml for the bold and italic is as follows,:

<text>
            <strong xmlns="http://www.w3.org/1999/xhtml">adasdasd</strong>
        </text>
<text>
        <em xmlns="http://www.w3.org/1999/xhtml">adsadas</em>
    </text>
<text>
    <strong xmlns="http://www.w3.org/1999/xhtml">adasdasd</strong>
</text>

<text>
    <em xmlns="http://www.w3.org/1999/xhtml">adsadas</em>
</text>
<xsl:template name="format" match="*[local-name()='strong'] | 
*[local-name()='em']">
    <xsl:variable name="tagName" select="name()" />
    <xsl:element name="{$tagName}" namespace="{$nSpace}">
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>
<xsl:template name="format" match="*[local-name()='strong'] | *[local-name()='em']">
    <xsl:variable name="tagName" select="name()" />
    <xsl:element name="{$tagName}" namespace="{$nSpace}">
        <xsl:copy-of select="@*" />
        <xsl:apply-templates />
    </xsl:element>
</xsl:template>
<text><strong>adasdasd</strong></text>


<text><em>adsadas</em></text>
<text><strong>adasdasd</strong></text>

<text><em>adsadas</em></text>

It is working fine for Bold and Italic.
But, I tried 4 ways for underline.
1)Enter consecutive text in that RTF field

    <text>Good Morning Have a nice <span xmlns="http://www.w3.org/1999/xhtml" 
style="text-decoration: underline;">Day</span></text>
  1. Enter consecutive text in that RTF field

 
<text>Good Morning Have a nice <span xmlns="http://www.w3.org/1999/xhtml" 
style="text-decoration: underline;">Day</span></text>
2)Enter a single word
  1. Enter a single word
<text>
            <div xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">Welcome</div>
        </text><br>
<text>
    <div xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">Welcome</div>
</text>

3)Enter text and press ENTER Key

  1. Enter text and press ENTER Key
<text>
    <p xmlns="http://www.w3.org/1999/xhtml">jhoiohad</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml">asuhdoahsoid</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">ahsdhaoiodia</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml">asdasd</p>
</text><br>
<text>
    <p xmlns="http://www.w3.org/1999/xhtml">jhoiohad</p>
    <p xmlns="http://www.w3.org/1999/xhtml">asuhdoahsoid</p>
    <p xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">ahsdhaoiodia</p>
    <p xmlns="http://www.w3.org/1999/xhtml">asdasd</p>
</text>

4)Enter text and press SHIFT + ENTER key

  1. Enter text and press SHIFT + ENTER key
<text>
huiuiioasiodio
<br xmlns="http://www.w3.org/1999/xhtml"></br>
iohoshiofhiohsd
<br xmlns="http://www.w3.org/1999/xhtml"></br>
<span xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">iosiohfioio</span>
<br xmlns="http://www.w3.org/1999/xhtml"></br>
uisuidfuiuisdhf
</text><br>
<text>
    huiuiioasiodio
    <br xmlns="http://www.w3.org/1999/xhtml">
    iohoshiofhiohsd
    <br xmlns="http://www.w3.org/1999/xhtml">
    <span xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">iosiohfioio</span>
    <br xmlns="http://www.w3.org/1999/xhtml">
    uisuidfuiuisdhf
</text>

I don't know how to handle for underline tag. Because different tag elements are generated. In the published file I need to get like this
 :

<text><u>...</u></text><br>
<text><u>...</u></text><br>

How to acheiveachieve this. Can anyone help me
Suggestions Welcome.Thanks in Advance.?

I have a requirement that I need to handle B(Bold), I(Italic) and U(underline) tag. We are using XSLT and XPath. I have an RTF field named <text>......</text>. I entered some text in this RTF field and made it as bold and Italic The source xml for the bold and italic is as follows,

<text>
            <strong xmlns="http://www.w3.org/1999/xhtml">adasdasd</strong>
        </text>
<text>
        <em xmlns="http://www.w3.org/1999/xhtml">adsadas</em>
    </text>
<xsl:template name="format" match="*[local-name()='strong'] | 
*[local-name()='em']">
    <xsl:variable name="tagName" select="name()" />
    <xsl:element name="{$tagName}" namespace="{$nSpace}">
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>
<text><strong>adasdasd</strong></text>


<text><em>adsadas</em></text>

It is working fine for Bold and Italic.
But, I tried 4 ways for underline.
1)Enter consecutive text in that RTF field

    <text>Good Morning Have a nice <span xmlns="http://www.w3.org/1999/xhtml" 
style="text-decoration: underline;">Day</span></text>

 2)Enter a single word
<text>
            <div xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">Welcome</div>
        </text><br>

3)Enter text and press ENTER Key

<text>
    <p xmlns="http://www.w3.org/1999/xhtml">jhoiohad</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml">asuhdoahsoid</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">ahsdhaoiodia</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml">asdasd</p>
</text><br>

4)Enter text and press SHIFT + ENTER key

<text>
huiuiioasiodio
<br xmlns="http://www.w3.org/1999/xhtml"></br>
iohoshiofhiohsd
<br xmlns="http://www.w3.org/1999/xhtml"></br>
<span xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">iosiohfioio</span>
<br xmlns="http://www.w3.org/1999/xhtml"></br>
uisuidfuiuisdhf
</text><br>

I don't know how to handle for underline tag. Because different tag elements are generated. In the published file I need to get like this
 

<text><u>...</u></text><br>

How to acheive this. Can anyone help me
Suggestions Welcome.Thanks in Advance.

I have a requirement that I need to handle B  (Bold), I  (Italic) and U  (underline) tags. We are using XSLT and XPath.

I have an RTF field named <text>......</text>.

I entered some text in this RTF field and made it Bold and Italic, the source xml for the bold and italic is as follows:

<text>
    <strong xmlns="http://www.w3.org/1999/xhtml">adasdasd</strong>
</text>

<text>
    <em xmlns="http://www.w3.org/1999/xhtml">adsadas</em>
</text>
<xsl:template name="format" match="*[local-name()='strong'] | *[local-name()='em']">
    <xsl:variable name="tagName" select="name()" />
    <xsl:element name="{$tagName}" namespace="{$nSpace}">
        <xsl:copy-of select="@*" />
        <xsl:apply-templates />
    </xsl:element>
</xsl:template>
<text><strong>adasdasd</strong></text>

<text><em>adsadas</em></text>

It is working fine for Bold and Italic.
But, I tried 4 ways for underline.

  1. Enter consecutive text in that RTF field
<text>Good Morning Have a nice <span xmlns="http://www.w3.org/1999/xhtml" 
style="text-decoration: underline;">Day</span></text>
  1. Enter a single word
<text>
    <div xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">Welcome</div>
</text>
  1. Enter text and press ENTER Key
<text>
    <p xmlns="http://www.w3.org/1999/xhtml">jhoiohad</p>
    <p xmlns="http://www.w3.org/1999/xhtml">asuhdoahsoid</p>
    <p xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">ahsdhaoiodia</p>
    <p xmlns="http://www.w3.org/1999/xhtml">asdasd</p>
</text>
  1. Enter text and press SHIFT + ENTER key
<text>
    huiuiioasiodio
    <br xmlns="http://www.w3.org/1999/xhtml">
    iohoshiofhiohsd
    <br xmlns="http://www.w3.org/1999/xhtml">
    <span xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">iosiohfioio</span>
    <br xmlns="http://www.w3.org/1999/xhtml">
    uisuidfuiuisdhf
</text>

I don't know how to handle for underline tag. Because different tag elements are generated. In the published file I need to get like this:

<text><u>...</u></text><br>

How to achieve this?

Post Migrated Here from stackoverflow.com (revisions)
Source Link

Handling Underline tag in Tridion 2013

I have a requirement that I need to handle B(Bold), I(Italic) and U(underline) tag. We are using XSLT and XPath. I have an RTF field named <text>......</text>. I entered some text in this RTF field and made it as bold and Italic The source xml for the bold and italic is as follows,

<text>
            <strong xmlns="http://www.w3.org/1999/xhtml">adasdasd</strong>
        </text>
<text>
        <em xmlns="http://www.w3.org/1999/xhtml">adsadas</em>
    </text>

I handled both Bold and Italic tag in this following way.

<xsl:template name="format" match="*[local-name()='strong'] | 
*[local-name()='em']">
    <xsl:variable name="tagName" select="name()" />
    <xsl:element name="{$tagName}" namespace="{$nSpace}">
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

In the published file I'm getting the tag element as expected

<text><strong>adasdasd</strong></text>


<text><em>adsadas</em></text>

It is working fine for Bold and Italic.
But, I tried 4 ways for underline.
1)Enter consecutive text in that RTF field

    <text>Good Morning Have a nice <span xmlns="http://www.w3.org/1999/xhtml" 
style="text-decoration: underline;">Day</span></text>

2)Enter a single word
<text>
            <div xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">Welcome</div>
        </text><br>

3)Enter text and press ENTER Key

<text>
    <p xmlns="http://www.w3.org/1999/xhtml">jhoiohad</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml">asuhdoahsoid</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">ahsdhaoiodia</p>
                
    
                <p xmlns="http://www.w3.org/1999/xhtml">asdasd</p>
</text><br>

4)Enter text and press SHIFT + ENTER key

<text>
huiuiioasiodio
<br xmlns="http://www.w3.org/1999/xhtml"></br>
iohoshiofhiohsd
<br xmlns="http://www.w3.org/1999/xhtml"></br>
<span xmlns="http://www.w3.org/1999/xhtml" style="text-decoration: underline;">iosiohfioio</span>
<br xmlns="http://www.w3.org/1999/xhtml"></br>
uisuidfuiuisdhf
</text><br>

I don't know how to handle for underline tag. Because different tag elements are generated. In the published file I need to get like this

<text><u>...</u></text><br>

How to acheive this. Can anyone help me
Suggestions Welcome.Thanks in Advance.