我有一個字符串,可能有換行符和撇號。我需要替換兩者。我有以下XSL代碼:XSL 1.0如何替換字符串中的兩個不同的東西
<xsl:call-template name="replaceapostrophes">
<xsl:with-param name="string">
<xsl:call-template name="replacelinefeeds">
<xsl:with-param name="string" select="hl7:text/hl7:paragraph"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
<!-- template for replacing line feeds with <br> tags for page display -->
<xsl:template name="replacelinefeeds">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,' ')">
<xsl:value-of select="substring-before($string,' ')"/>
<br/>
<xsl:call-template name="replacelinefeeds">
<xsl:with-param name="string" select="substring-after($string,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template for replacing html encoded apostrophes for page display -->
<xsl:template name="replaceapostrophes">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string, '&#39;')">
<xsl:value-of select="substring-before($string,'&#39;')"/>'<xsl:call-template name="replaceapostrophes">
<xsl:with-param name="string" select="substring-after($string,'&#39;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
這是XML代碼:
<text>
<paragraph>Adding apostrophe to the patient&#39;s instructions
and checking for a second line</paragraph>
</text>
然而,當這個運行時,我發現了撇號佔了,但不換行。
Adding apostrophe to the patient's instructions and checking for a second line
而不是
Adding apostrophe to the patient's instructions
and checking for a second line
它正常工作,如果有一個在相同的字符串一個或另一個但不是兩者。
有沒有不同的方式,我需要做到這些?
謝謝
切換它們,它工作正常。謝謝 – jjasper0729