如何在XSLT的value-of select标签字符串中添加换行符适配RSA Archer富文本
错误原因
- 你直接在
concat()函数中写入<BR>标签时,XSLT解析器会将其识别为XML节点而非文本内容,直接抛出语法错误 - XPath语法中不支持
\n转义字符,该内容会被作为普通字符输出,无法产生换行效果
解决方案
直接在XSLT模板中嵌套你需要输出的HTML标签,不要将标签放入concat()函数拼接,修改后的完整代码如下:
<NewSourceName> <xsl:for-each select="CORRELATION/EXPLOITS/EXPLT_SRC/EXPLT_LIST/EXPLT"> <xsl:variable name="Source" select="../../SRC_NAME"/> <xsl:variable name="Link" select="LINK"/> <xsl:variable name="Description" select="DESC"/> <xsl:variable name="Reference" select="REF"/> <p> Source: <xsl:value-of select="$Source"/><br/> Reference: <xsl:value-of select="$Reference"/><br/> Description: <xsl:value-of select="$Description"/><br/> Link: <xsl:value-of select="$Link"/> </p> <br/> </xsl:for-each> </NewSourceName>
如果你的XSLT声明中输出模式设置为method="text",无法直接输出HTML标签,可以使用disable-output-escaping属性强制输出尖括号,写法如下:
<NewSourceName> <xsl:for-each select="CORRELATION/EXPLOITS/EXPLT_SRC/EXPLT_LIST/EXPLT"> <xsl:variable name="Source" select="../../SRC_NAME"/> <xsl:variable name="Link" select="LINK"/> <xsl:variable name="Description" select="DESC"/> <xsl:variable name="Reference" select="REF"/> <xsl:value-of select="concat('<p>Source: ', $Source, '<br>')" disable-output-escaping="yes"/> <xsl:value-of select="concat('Reference: ', $Reference, '<br>')" disable-output-escaping="yes"/> <xsl:value-of select="concat('Description: ', $Description, '<br>')" disable-output-escaping="yes"/> <xsl:value-of select="concat('Link: ', $Link, '</p><br>')" disable-output-escaping="yes"/> </xsl:for-each> </NewSourceName>
两种写法输出的HTML结构都符合RSA Archer富文本字段的解析规则,传入后会自动渲染出你需要的换行效果。
内容的提问来源于stack exchange,提问作者LarMedina75
相关产品推荐
相关产品推荐

