
[英]How to extract childelement from parent tag in nested xml via xslt?
[英]how to parent tag with nested tag
我有一个看起来像这样的XML文件:
<SNS>
<SN>aaaa</SN>
<SN>bbbb</SN>
<LN>cccc</LN>
<SN>dddd</SN>
<SN>eeee</SN>
<LN>ffff</LN>
</SNS>
要求的输出:
<SN>aaaa</SN>
<LN>cccc</LN>
<SN>bbbb</SN>
<LN>cccc</LN>
<SN>dddd</SN>
<LN>ffff</LN>
<SN>eeee</SN>
<LN>ffff</LN>
如何使用<LN>
添加每个<SN>
标签?
只需处理所有SN
元素,并在其模板中复制以下同级LN
:
<xsl:template match="SNS">
<xsl:apply-templates select="SN"/>
</xsl:template>
<xsl:template match="SN">
<xsl:copy-of select="., following-sibling::LN[1]"/>
</xsl:template>
https://xsltfiddle.liberty-development.net/pPzifq2
在XSLT 3中,您还可以简单地处理每个SN
及其同级LN
并通过身份转换来推送它们:
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="SNS">
<xsl:apply-templates select="SN!(., following-sibling::LN[1])"/>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.