Xslt 如何在不分析替换值的情况下用尖括号替换文本?
我有这个:Xslt 如何在不分析替换值的情况下用尖括号替换文本?,xslt,xquery,Xslt,Xquery,我有这个: replace("Both cruciate ligaments are well visualized and are intact.", ".", ".<br>") 但是我不想输出转义的尖括号,而是实际的括号。当我运行代码时,我得到: Both cruciate ligaments are well visualized and are intact.<br> 我想: Both cru
replace("Both cruciate ligaments are well visualized and are intact.",
".",
".<br>")
但是我不想输出转义的尖括号,而是实际的括号。当我运行代码时,我得到:
Both cruciate ligaments are well visualized and are intact.<br>
我想:
Both cruciate ligaments are well visualized and are intact.<br>
两条交叉韧带均清晰可见且完好无损。
我怎样才能做到这一点?我不能直接使用尖括号作为替换值,因为我得到了一个错误
编辑 我有一个样式表,它接收一个文本文件,该文本文件被注入一个HTML文件(来自样式表)。我获取一个XML(临床文档)和一个文本文件,并将它们与样式表合并在一起。例如,我有: 放射学报告
姓名:约翰,多伊
出生日期:1982-02-25
这里是注入文本
文本必须在回车时换行,并且必须在单词级别换行。我确实设法做到了后者,但我没有找到一种方法来断线。我想在文件中找到一个替换为
的“LF”,这样一旦呈现页面,我就可以看到换行符。如果要输出节点而不是简单的字符串,需要使用
xsl:analyze string
。以下是一个例子:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="text">
<xsl:analyze-string select="." regex="\.">
<xsl:matching-substring>
<xsl:value-of select="."/><br/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
输入为
<text>Both cruciate ligaments are well visualized and are intact.</text>
两条交叉韧带均清晰可见且完好无损。
转换结果是
Both cruciate ligaments are well visualized and are intact.<br>
两条交叉韧带均清晰可见且完好无损。
如果要输出节点而不仅仅是字符串,则需要使用xsl:analyze string
。以下是一个例子:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="text">
<xsl:analyze-string select="." regex="\.">
<xsl:matching-substring>
<xsl:value-of select="."/><br/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
输入为
<text>Both cruciate ligaments are well visualized and are intact.</text>
两条交叉韧带均清晰可见且完好无损。
转换结果是
Both cruciate ligaments are well visualized and are intact.<br>
两条交叉韧带均清晰可见且完好无损。
如果要输出节点而不仅仅是字符串,则需要使用xsl:analyze string
。以下是一个例子:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="text">
<xsl:analyze-string select="." regex="\.">
<xsl:matching-substring>
<xsl:value-of select="."/><br/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
输入为
<text>Both cruciate ligaments are well visualized and are intact.</text>
两条交叉韧带均清晰可见且完好无损。
转换结果是
Both cruciate ligaments are well visualized and are intact.<br>
两条交叉韧带均清晰可见且完好无损。
如果要输出节点而不仅仅是字符串,则需要使用xsl:analyze string
。以下是一个例子:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="text">
<xsl:analyze-string select="." regex="\.">
<xsl:matching-substring>
<xsl:value-of select="."/><br/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
输入为
<text>Both cruciate ligaments are well visualized and are intact.</text>
两条交叉韧带均清晰可见且完好无损。
转换结果是
Both cruciate ligaments are well visualized and are intact.<br>
两条交叉韧带均清晰可见且完好无损。
马丁·霍宁的答案是一个非常好的方法
使用简单模板查找相关文本是另一种方法:
<xsl:variable name="magic-string"
select='"Both cruciate ligaments are well visualized and are intact."'/>
...
<xsl:template match="text()
[contains(.,$magic-string)]">
<xsl:value-of select="substring-before(.,$magic-string)"/>
<xsl:value-of select="$magic-string"/>
<br/>
<xsl:value-of select="substring-after(.,$magic-string)"/>
</xsl:template>
...
在这两种情况下,使用HTML输出方法将空的br
元素序列化为
,而不是
注意:我在这里假设您希望在这个特定的句子之后有一个
br
,而不是在每次出现句号之后都有一个,这就是Martin Honnen对这个问题的解释。Martin Honnen的回答是一个非常好的方法
使用简单模板查找相关文本是另一种方法:
<xsl:variable name="magic-string"
select='"Both cruciate ligaments are well visualized and are intact."'/>
...
<xsl:template match="text()
[contains(.,$magic-string)]">
<xsl:value-of select="substring-before(.,$magic-string)"/>
<xsl:value-of select="$magic-string"/>
<br/>
<xsl:value-of select="substring-after(.,$magic-string)"/>
</xsl:template>
...
在这两种情况下,使用HTML输出方法将空的br
元素序列化为
,而不是
注意:我在这里假设您希望在这个特定的句子之后有一个
br
,而不是在每次出现句号之后都有一个,这就是Martin Honnen对这个问题的解释。Martin Honnen的回答是一个非常好的方法
使用简单模板查找相关文本是另一种方法:
<xsl:variable name="magic-string"
select='"Both cruciate ligaments are well visualized and are intact."'/>
...
<xsl:template match="text()
[contains(.,$magic-string)]">
<xsl:value-of select="substring-before(.,$magic-string)"/>
<xsl:value-of select="$magic-string"/>
<br/>
<xsl:value-of select="substring-after(.,$magic-string)"/>
</xsl:template>
...
在这两种情况下,使用HTML输出方法将空的br
元素序列化为
,而不是
注意:我在这里假设您希望在这个特定的句子之后有一个
br
,而不是在每次出现句号之后都有一个,这就是Martin Honnen对这个问题的解释。Martin Honnen的回答是一个非常好的方法
使用简单模板查找相关文本是另一种方法:
<xsl:variable name="magic-string"
select='"Both cruciate ligaments are well visualized and are intact."'/>
...
<xsl:template match="text()
[contains(.,$magic-string)]">
<xsl:value-of select="substring-before(.,$magic-string)"/>
<xsl:value-of select="$magic-string"/>
<br/>
<xsl:value-of select="substring-after(.,$magic-string)"/>
</xsl:template>
...
在这两种情况下,使用HTML输出方法将空的br
元素序列化为
,而不是
注意:我在这里假设您希望在这个特定的句子之后有一个
br
,而不是在每次出现句号之后都有一个,这就是Martin Honnen对问题的解释。取决于您的实现,显示此文本的任何内容都可能会取消角括号。是否要将文字点
替换为
元素?或者任何角色?我想知道带有replace
调用的第二个参数的示例是否不需要将点转义为'\.
。。根据您的实现,显示此文本的任何内容都可能会取消对尖括号的转义。是否要将文字点
替换为
元素?或者任何角色?我想知道带有replace
调用的第二个参数的示例是否不需要将点转义为'\.
。。根据您的实现,显示此文本的任何内容都可能会取消对尖括号的转义。是否要将文字点
替换为
元素?或者任何角色?我想知道带有replace
调用的第二个参数的示例是否不需要将点转义为'\.
。。根据您的实现,显示这一点的是什么