ArnaudTheDevelopper
ArnaudTheDevelopper

Reputation: 81

To delete the last character when it is a point with xsl

I try to delete the last character in the balises of a XML with XSL

For example

<hello>
...
<essai1>essai1</essai1>
...
<essai2>essai2 .</essai2>
...
</hello>

I would like the result unless point

<hello>
...
<essai1>essai1</essai1>
...
<essai2>essai2 </essai2>
...
</hello>

Could you help me ? Thanks, Arnaud

Upvotes: 0

Views: 1069

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117018

The question is a bit too broad, IMHO. The following stylesheet will remove a trailing period from any text node in the entire document, leaving everything else as is:

XSLT 1.0

<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="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="text()[substring(., string-length()) ='.']">
    <xsl:value-of select="substring(., 1, string-length() - 1)"/>
</xsl:template>

</xsl:stylesheet>

Upvotes: 1

Related Questions