如何在 Tag 后检查换行符 ( )</Underline>并需要在 xslt 代码中替换为 to <br/> tag



我有XML文件需要使用XSLT代码转换为HTML

请参阅XML文件:

<?xml version="1.0" encoding="UTF-8"?><Lesson><Title>Merged Words_G1L5</Title><IntroBlock><ParaBlock><RichText>Materials: Exercise books and pencils</RichText></ParaBlock></IntroBlock><Topic><Title>Underlines – 15 minutes</Title><ParaBlock><CustomNote><SimpleBlock><RichText>
<Underline>ACHIEVE</Underline>
Fill in the Blank: go, wear, quiet, bus, I
1. the pupils are _____.
2. My parents are _____.
3. This school is a _____.
4. ____ am very tall.
5. They _____ sandals.</RichText></SimpleBlock></CustomNote></ParaBlock></Topic></Lesson>

通常换行符(&#10(从我现有的代码转换为<br/>标签

现有代码:1.检查换行并替换为<br/>标签时:

<xsl:template match="text()">
<xsl:param name="text" select="."/>
<xsl:variable name="starttext" select="substring-before(concat($text,'&#10;'),'&#10;')" />
<xsl:variable name="nexttext" select="substring-after($text,'&#10;')"/>
<xsl:if test="normalize-space($starttext)">
<xsl:value-of select="$starttext"/>
<xsl:if test="normalize-space($nexttext)">
<br />
</xsl:if>
</xsl:if>
<xsl:if test="contains($text,'&#10;')">
<xsl:apply-templates select=".">
<xsl:with-param name="text" select="$nexttext"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>

现有代码:2。与下划线相关:

<xsl:template match="Underline">
<xsl:if test="text() or *">
<u>
<xsl:apply-templates/>
</u>
</xsl:if>
</xsl:template>

现有代码:3。与富文本相关:

<xsl:template match="RichText">
<xsl:if test="text() or *">
<p>
<xsl:apply-templates/>
</p>
</xsl:if>
</xsl:template>

上面提到的是我现有的代码。我需要一个关于如何在<RichText>下的</Underline>标记和</UnderLine>标记之后检查换行符(&#10(的解决方案,因为正常情况下我的代码工作正常,但仅在</UnderLine>标记位于<RichText>之下时才导致任何人,请建议如何在我的代码中的</UnderLine>标签后检查换行符(&#10(

当前问题:当前发行


要求输出:要求的输出

您在以下条件下输出<br />

<xsl:if test="normalize-space($starttext)">

当文本以换行符开头时,这种情况就不成立了——就像您的例子中一样。如果要保留开始换行,请删除该条件。

最新更新