在我的 XSLT 转换中,我需要使用两个分析字符串来处理一个节点。它们一个接一个地工作得很好,但我不知道如何将它们组合在一起。
XML 文档如下所示:
<article>
<title>Article 1</title>
<text><![CDATA[Lorem ipsum dolor sit amet, s consectetur adipiscing elit. Donec lorem diam, eleifend sed mollis id, condimentum in velit.
Sed sit amet erat ac mauris adipiscing elementum. Pellentesque eget quam augue, id faucibus magna.
Ut malesuada arcu eu elit sodales sodales. Morbi tristique porttitor tristique. Praesent eget vulputate dui. Cras ut tortor massa, at faucibus ligula.]]></text>
</article>
这是我的 XSLT:
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Page title</title>
</head>
<body>
<xsl:for-each select="article">
<h1><xsl:value-of select="./title"/></h1>
<!-- This adds paragraphs tags instead of empty lines in the text -->
<xsl:analyze-string select="./text" regex="
">
<xsl:non-matching-substring>
<p>
<xsl:value-of select="." disable-output-escaping="yes"/>
</p>
</xsl:non-matching-substring>
</xsl:analyze-string>
<!-- This is Czech language specific. It looks for ' s ' (or other letter) and changes second space for . So after that it is ' s '. -->
<xsl:analyze-string select="./text" regex="(\s[k/K/s/S/v/V/z/Z]\s)">
<xsl:matching-substring>
<xsl:text> </xsl:text>
<xsl:value-of select="replace(., ' ','')" disable-output-escaping="yes"/>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</body>
</html>
</xsl:template>
我需要在生成的文本上应用两个分析字符串,以便有<p>
段落标签并添加
到正确的位置。
我想要的输出如下所示:
<h1>Article 1</h1>
<p>Lorem ipsum dolor sit amet, s consectetur adipiscing elit. Donec lorem diam, eleifend sed mollis id, condimentum in velit.</p>
<p>Sed sit amet erat ac mauris adipiscing elementum. Pellentesque eget quam augue, id faucibus magna.</p>
<p>Ut malesuada arcu eu elit sodales sodales. Morbi tristique porttitor tristique. Praesent eget vulputate dui. Cras ut tortor massa, at faucibus ligula.</p>
知道怎么做吗?感谢您抽出宝贵的时间来帮助我。