How to remove a space in XML using stylesheet using RegEx -


i have xml , looking finding particular tag (in case "firstname") , removing space in value if there - character before space.

in other words, want keep spaces if there no - front of them. want using xsl stylesheet regex matching , replace function.

expected result sam-louise, removing space between "sam-" , "louise"

<?xml version="1.0" encoding="utf-8"?> <ncv version="1.14">     <invoice>         <customer>             <customerid>12785</customerid>             <firstname>sam- louise</firstname>             <lastname>jones</lastname>         </customer>     </invoice> </ncv> 

this 1 possible xslt :

<xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">     <xsl:output method="html" encoding="utf-8" indent="yes" />     <xsl:strip-space elements="*"/>      <xsl:template match="firstname">         <firstname>             <xsl:value-of select="replace(., '-\s+', '-')"/>         </firstname>     </xsl:template>      <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()"/>         </xsl:copy>     </xsl:template> </xsl:transform> 

xsltransform.net demo

output :

<ncv version="1.14">    <invoice>       <customer>          <customerid>12785</customerid>          <firstname>sam-louise</firstname>          <lastname>jones</lastname>       </customer>    </invoice> </ncv> 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -