xslt-2.0 - 在 XSLT 中的节点之间添加空格
问题描述
XML
文件 :
<string-name>
<surname>Husebo</surname><given-names>BS</given-names>
</string-name>, <string-name>
<surname>Ballard</surname> <given-names>C</given-names></string-name>
XSL :
<xsl:template match="surname">
<xsl:choose>
<xsl:when test = "following-sibling::node()[not(./*) and normalize-space(.)='']">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
输出 : Husebo BS, Ballard C
检查空格后,我想在< surname>
和< given-name>
标记之间添加空格。ex - 首先,在检查是否应该添加空格之后,等等< string-name>
之间没有空格。但是在标签中已经存在一个空格,因此不会在那里添加空格。请帮忙 !!!< surname>
< given-name>
< /surname>
2nd
< /string-name>
解决方案
使用此代码希望它对您有所帮助:
<xsl:template match="surname[not(following-sibling::node()[1][self::text()[. = ' ']])]">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:template>
如果您想更具体,请检查紧随其后的兄弟姐妹是否给定名称,然后使用以下代码:
<xsl:template match="surname[not(following-sibling::node()[1][self::text()[. = ' ']]) and following-sibling::node()[1][self::given-names]]">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:template>
推荐阅读
- r - 根据日期分配新变量
- javascript - 具有先前状态保存的功能
- angular - Angular Material Stepper not working on StackBlitz
- c# - 当我单击按钮转到 winforms 中的另一个表单时,应用程序冻结
- java - 打开新的命令提示符并从在命令提示符中运行的 Java 程序发送命令
- c# - MvvmCross 6.0:如何在初始化时将参数传递给 App?
- blockchain - 如何以编程方式部署和验证(公共源代码)以太坊智能合约?
- google-chrome-extension - 获取标签 URL,复制到新标签,更改域中的某些内容
- c# - .NET 如何通过 Windows 虚拟 COM 端口连续发送和接收 600k 字节块?
- wordpress - wordpress 中每种语言都需要一个 dmscookie 代码