I am trying to concatenate in a single element, all tags with the same name (my XSLT already does this), the problem is that the text has a hyphen at the beginning and a blank space at the end that I must remove, I can not do this last part. I have this input:
<LIST>
<PLACE>
<level>-this </level>
<level>-Is </level>
<level>What</level>
<level>-I</level>
<level>Want </level>
</PLACE>
</LIST>
And need an output like:
<LIST>
<PLACE>
<level>thisIsWhatIWant</level>
</PLACE>
</LIST>
Im using this XSLT:
<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="PLACE">
<PLACE>
<level>
<!-- I tried this to eliminate the hyphen -->
<xsl:value-of select="translate(.,'-','')"/>
<!-- and this to eliminate the white space at the end of the elements -->
<xsl:value-of select="translate(.,' ','')"/>
<xsl:value-of select="normalize-space(concat(level[1],level[2],level[3],level[4],level[5]))" />
</level>
</PLACE>
</xsl:template>
</xsl:stylesheet>
How can I modify my xslt to eliminate the white spaces and the hyphen from the text before concatenating it.
Thanks
Use this:
<?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="PLACE">
<PLACE>
<level>
<xsl:apply-templates/>
</level>
</PLACE>
</xsl:template>
<xsl:template match="level">
<xsl:value-of select="normalize-space(translate(.,'-',''))"/>
</xsl:template>
</xsl:stylesheet>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.