XSL Remove a line break from text

2019-05-10 21:13发布

I would like to remove the line break that follows all text that says See the Exhibit "

Unwanted linebreak as shown in notepadd++:

alt text http://img13.imageshack.us/img13/9803/clcflinebreak.png

This is what I have so far:

<xsl:template match="p">
<!-- output everything but the See the exhibit text should have the line break removed -->

</xsl:template>

Any ideas? Thanks!

标签: xml xslt
2条回答
beautiful°
2楼-- · 2019-05-10 21:27
        <!-- Get text. Replace all “break with “ -->
        <xsl:variable name="linebreak">
            <xsl:text>
</xsl:text>
        </xsl:variable>
        <xsl:variable name="text">
            <xsl:call-template name="replace-string">
                <xsl:with-param name="text" select="."/>
                <xsl:with-param name="replace" select="concat('“',$linebreak)" />
                <xsl:with-param name="with" select="string('“')"/>
            </xsl:call-template>
        </xsl:variable>


        <xsl:value-of select="$text"/>
查看更多
Melony?
3楼-- · 2019-05-10 21:37

If you're using your transform to generate HTML output, the simplest approach is usually:

<xsl:value-of select="normalize-space($text)"/>

normalize-space strips leading and trailing whitespace, and replaces runs of multiple whitespace characters within the string with a single space.

To remove exactly a trailing CR/LF pair:

<xsl:choose>
   <xsl:when test="substring(., string-length(.)-1, 2) = '&#xD;&#xA;'">
      <xsl:value-of select="substring(., 1, string-length(.)-2)"/>
   </xsl:when>
   <xsl:otherwise>
      <xsl:value-of select="."/>
   </xsl:otherwise>
</xsl:choose>
查看更多
登录 后发表回答