Home > Net >  how to eliminate white space between words and symbol in a text and then merge the text of two eleme
how to eliminate white space between words and symbol in a text and then merge the text of two eleme

Time:08-09

I have a XML that have a white space in the text (After the word LIVE) and a point that I need to eliminate, and then merge the elements into one element, I can not eliminate the white space in the text.

I have this XML

<HOUSE> 
    <TS>
        <DIRECTION>
            <DESCRIPTION>.Hugo_Street</DESCRIPTION>
            <DESCRIPTION>LIVE _CLOSE</DESCRIPTION>
            <DESCRIPTION>FLO</DESCRIPTION>
            <DESCRIPTION>0000</DESCRIPTION>
        </DIRECTION>
    </TS>
</HOUSE>

And I need something like

<HOUSE> 
    <TS>
        <DIRECTION>
            <DESCRIPTION>Hugo_StreetLIVE_CLOSE</DESCRIPTION>
        </DIRECTION>
    </TS>
</HOUSE>

Im using this solution that I saw in another post but it does not eliminate de the white space after LIVE :

<?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:strip-space elements="*"/>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="DIRECTION">
    <DIRECTION>
      <DESCRIPTION>
          <xsl:apply-templates select="DESCRIPTION[1]"/>
          <xsl:apply-templates select="DESCRIPTION[2]"/>
      </DESCRIPTION>
    </DIRECTION>
  </xsl:template>
  
  <xsl:template match="DESCRIPTION">
    <xsl:value-of select="normalize-space(translate(.,'.',''))"/>
  </xsl:template>
</xsl:stylesheet>

I tried to add this line to the template but that doesn't work either

<xsl:value-of select="normalize-space(translate(.,' ',''))"/>

any suggestions I can add in the code

CodePudding user response:

Using translate(.,'. ','') instead of translate(.,'.','') will eliminate both the dot and the space.

  • Related