C# 如何在<;之后检查换行(&;10)/下划线>;标记并需要替换为to<;br/>;xslt代码中的标记
我有XML文件需要转换成HTML使用XSLT代码 请参阅XML文件:C# 如何在<;之后检查换行(&;10)/下划线>;标记并需要替换为to<;br/>;xslt代码中的标记,c#,.net,xslt,C#,.net,Xslt,我有XML文件需要转换成HTML使用XSLT代码 请参阅XML文件: <?xml version="1.0" encoding="UTF-8"?><Lesson><Title>Merged Words_G1L5</Title><IntroBlock><ParaBlock><RichText>Materials: Exercise books and pencils</RichText></Par
<?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>
Merged Words\u G1l5材料:练习本和铅笔铅笔铅笔铅笔线–15分钟
实现
填空:走,穿,安静,公共汽车,我
1.学生们都是。
2.我的父母是。
3.这所学校是一所。
4. ____ 我很高。
5.它们是凉鞋。
通常情况下,换行符(
)从我的现有代码转换为
标记
现有代码:
1.检查换行并替换为
标记时:
<xsl:template match="text()">
<xsl:param name="text" select="."/>
<xsl:variable name="starttext" select="substring-before(concat($text,' '),' ')" />
<xsl:variable name="nexttext" select="substring-after($text,' ')"/>
<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,' ')">
<xsl:apply-templates select=".">
<xsl:with-param name="text" select="$nexttext"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="Underline">
<xsl:if test="text() or *">
<u>
<xsl:apply-templates/>
</u>
</xsl:if>
</xsl:template>
<xsl:template match="RichText">
<xsl:if test="text() or *">
<p>
<xsl:apply-templates/>
</p>
</xsl:if>
</xsl:template>
现有代码:2。与下划线相关:
<xsl:template match="text()">
<xsl:param name="text" select="."/>
<xsl:variable name="starttext" select="substring-before(concat($text,' '),' ')" />
<xsl:variable name="nexttext" select="substring-after($text,' ')"/>
<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,' ')">
<xsl:apply-templates select=".">
<xsl:with-param name="text" select="$nexttext"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="Underline">
<xsl:if test="text() or *">
<u>
<xsl:apply-templates/>
</u>
</xsl:if>
</xsl:template>
<xsl:template match="RichText">
<xsl:if test="text() or *">
<p>
<xsl:apply-templates/>
</p>
</xsl:if>
</xsl:template>
现有代码:3。与富文本相关:
<xsl:template match="text()">
<xsl:param name="text" select="."/>
<xsl:variable name="starttext" select="substring-before(concat($text,' '),' ')" />
<xsl:variable name="nexttext" select="substring-after($text,' ')"/>
<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,' ')">
<xsl:apply-templates select=".">
<xsl:with-param name="text" select="$nexttext"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="Underline">
<xsl:if test="text() or *">
<u>
<xsl:apply-templates/>
</u>
</xsl:if>
</xsl:template>
<xsl:template match="RichText">
<xsl:if test="text() or *">
<p>
<xsl:apply-templates/>
</p>
</xsl:if>
</xsl:template>
上面提到的是我现有的代码。
我需要一个解决方案来检查
标记之后的换行符(
)和
标记下的
标记,因为正常情况下我的代码工作正常,但只有当
标记位于
下时才会导致换行符(
)
任何人,请建议如何在我的代码中的
标记后检查换行(
)
??????。
当前问题:
所需输出:
您在以下条件下输出
:
<xsl:if test="normalize-space($starttext)">
当文本以换行符开头时,此条件不是真的-在您的示例中就是这样。如果要保留开头换行符,请删除该条件。谢谢您的建议,如果我删除了该条件,那么如何管理这种情况-“当文本以换行符开头”我如何检查的任何特定解决方案“tag位于tag和linefeed after下,您能提出建议吗?
下划线
后的换行符已经存在。您是移除它的人。谢谢Michael的建议,您知道我如何在if条件中检查
并将
替换为“”。因为我需要特别检查这件事,请建议?还有代码的顺序?我对XSLT代码非常陌生,请帮帮我…我们似乎在兜圈子。因为我需要在同一代码中检查这两个条件,有些文件需要此代码,有些文件有 个条件,但第一个条件覆盖到第二个条件。如何在同一代码中管理两者。