jmc430
asked on
Remove trailing period ... please help!!!!
Greetings,
I am attempting to remove the period at the end of a text element string, like this:
<SUB.HEAD>Here is a nice sub.headline.</SUB.HEAD>
I want it to read: "Here is a nice sub.headline" (without the final period)
However, the function I wrote currently removes all periods:
<xsl:value-of select="translate(.,'.','& #160;')"/>
So instead of the correct format as above, it appears like this:
"Here is a nice subheadline"
How can I simply remove the trailing/last character when it is a period?
Any advice or guidance is greatly appreciated. Thanks for helping me!
Best regards,
Jamie
I am attempting to remove the period at the end of a text element string, like this:
<SUB.HEAD>Here is a nice sub.headline.</SUB.HEAD>
I want it to read: "Here is a nice sub.headline" (without the final period)
However, the function I wrote currently removes all periods:
<xsl:value-of select="translate(.,'.','&
So instead of the correct format as above, it appears like this:
"Here is a nice subheadline"
How can I simply remove the trailing/last character when it is a period?
Any advice or guidance is greatly appreciated. Thanks for helping me!
Best regards,
Jamie
ASKER
Hi jkmyoung,
Thanks for responding!
The ends-with function is not available within the constraints of my production environment .... and the trailing period does not occur all the time... is there any other way to work around this?
Thanks so much for helping me!
Thanks for responding!
The ends-with function is not available within the constraints of my production environment .... and the trailing period does not occur all the time... is there any other way to work around this?
Thanks so much for helping me!
ASKER
I've also been tinkering around with this:
<xsl:choose>
<xsl:when test="substring(., string-length(.),1)='.'">
<xsl:value-of select="substring(., 1,string-length(.) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
but it's not doing anything ... I have no idea what is happening!
<xsl:choose>
<xsl:when test="substring(., string-length(.),1)='.'">
<xsl:value-of select="substring(., 1,string-length(.) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
but it's not doing anything ... I have no idea what is happening!
Did the 2nd suggestion:
<xsl:value-of select="substring(.,1,stri ng-length( .)-1)"/>
<xsl:value-of select="translate(substrin g(.,string -length(.) ),'.',' 60;')"/>
not work either?
eg. is the substring function available?
<xsl:value-of select="substring(.,1,stri
<xsl:value-of select="translate(substrin
not work either?
eg. is the substring function available?
ASKER
The substring function is available, but the 2nd suggestion did not work either ...
ASKER
can you help me with this?
<xsl:if test="string-length(transl ate(substr ing(.,stri ng-length( .)),'.','' ))!= 0">
<xsl:apply-templates/>
</xsl:if>
<xsl:if test="string-length(transl ate(substr ing(.,stri ng-length( .)),'.','' ))= 0">
<xsl:value-of select="translate(.,'.','& #160;')"/>
</xsl:if>
I am trying to do something similar that is also not working ...
<xsl:if test="string-length(transl
<xsl:apply-templates/>
</xsl:if>
<xsl:if test="string-length(transl
<xsl:value-of select="translate(.,'.','&
</xsl:if>
I am trying to do something similar that is also not working ...
how did it not work? What is that outputting?
may need your surrounding xslt code.
may need your surrounding xslt code.
ASKER
Basically it's like this:
<SUB.HEAD>Here is a nice sub.headline.</SUB.HEAD> => Should print "Here is a nice sub.headline"
<SUB.HEAD>I. SUBHEAD.</SUB.HEAD> => Should print "I. SUBHEAD"
<SUB.HEAD>II. "SUB HEAD."</SUB.HEAD> => Should print "II. "SUB HEAD."
<SUB.HEAD>new subheadline.</SUB.HEAD> => Should print "new subheadline"
Instead, all of my tests to just remove the trailing period are failing. Either all the periods get removed, or all the periods end up staying. I just want the final period to be removed - this is not happening often within the XML, but it is occurring often enough to cause grief amongst the Editors...
Thanks for helping me!
<SUB.HEAD>Here is a nice sub.headline.</SUB.HEAD> => Should print "Here is a nice sub.headline"
<SUB.HEAD>I. SUBHEAD.</SUB.HEAD> => Should print "I. SUBHEAD"
<SUB.HEAD>II. "SUB HEAD."</SUB.HEAD> => Should print "II. "SUB HEAD."
<SUB.HEAD>new subheadline.</SUB.HEAD> => Should print "new subheadline"
Instead, all of my tests to just remove the trailing period are failing. Either all the periods get removed, or all the periods end up staying. I just want the final period to be removed - this is not happening often within the XML, but it is occurring often enough to cause grief amongst the Editors...
Thanks for helping me!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i realize that the problem has to do with the fact that whitespace is existing and messing up my tests for ending with a period.
<xsl:if test="string-length(transl ate(substr ing(.,stri ng-length( .)),'.','' ))!= 0">
<xsl:apply-templates/>
</xsl:if>
<xsl:if test="string-length(transl ate(substr ing(.,stri ng-length( .)),'.','' ))= 0">
<xsl:value-of select="translate(substrin g(.,string -length(.) ),'.',' 60;')"/>
</xsl:if>
how do i fix this so that it first normalize(s)-space (removes all trailing whitespace) before doing the test?
thanks so much for helping me..
<xsl:if test="string-length(transl
<xsl:apply-templates/>
</xsl:if>
<xsl:if test="string-length(transl
<xsl:value-of select="translate(substrin
</xsl:if>
how do i fix this so that it first normalize(s)-space (removes all trailing whitespace) before doing the test?
thanks so much for helping me..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks so much Geert! you're awesome! it works!! :)
welcome
<xsl:choose>
<xsl:when test ="ends-with(.,'.')">
<xsl:value-of select="substring(.,1,stri
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
If this happens a lot:
<xsl:value-of select="substring(.,1,stri
<xsl:value-of select="translate(substrin
or possibly:
<xsl:value-of select="substring(.,1,stri
<xsl:if test="not (ends-with(.,'.'))">
<xsl:value-of select="substring(.,string
</xsl:if>