Xslt用分隔符连接两个节点列表

我试图将两个具有子元素的节点列表用字符串连接起来,但是我丢失了子元素中的xml标签

输入: 节点1:hello I am trying <abc> some </abc> xslt code

node2:but not working

预期产量

hello I am trying <abc> some </abc> xslt code,but not working

tgbbhu 回答:Xslt用分隔符连接两个节点列表

如果有两个包含包含所显示内容的元素节点的序列,并且想要在这些节点之间创建带有分隔符public class Envelope { [Key] public Guid EnvelopeId { get; set; } public virtual ICollection<Recipient> Recipients { get; set; } = new Hashset<Recipient>(); ... } 的输出,则一种方法是将元素推入添加分隔符:

,

https://xsltfiddle.liberty-development.net/pPJ8LVh

如果您想使用<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all" version="3.0"> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="root"> <xsl:param name="seq1" select="node1,node2"/> <xsl:copy> <xsl:apply-templates select="$seq1"/> </xsl:copy> </xsl:template> <xsl:template match="node1 | node2"> <xsl:if test="position() > 1">,</xsl:if> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet> 在字符串级别上工作,则首先需要对内容进行序列化,例如

string-join

https://xsltfiddle.liberty-development.net/pPJ8LVh/1

  <xsl:output method="text"/>

  <xsl:template match="root">
      <xsl:param name="seq1" select="node1,node2"/>
      <xsl:copy>
          <xsl:value-of select="$seq1 ! serialize(node())" separator=","/>
      </xsl:copy>
  </xsl:template>

https://xsltfiddle.liberty-development.net/pPJ8LVh/2

如您所见,最后两个示例创建了以文本形式输出的字符串,看起来您很可能想像第一个建议中那样创建一个结果节点。

本文链接:https://www.f2er.com/3164124.html

大家都在问