0
上层标签检查情况我有这样的要求,我只需要填入下<Section>
的<Group>
标签,如果下<Data>
的<Group>
标签不存在。我无法获得我想要的正确输出。例如:在XSLT 2.0
INPUT
<Record>
<Data>
<ID>1234DFD57</ID>
<Group>
<abc-KD>243fds</abc-KD>
</Group>
<Section>
<ID>33-2311</ID>
<Group>
<abc-KD>NORM</abc-KD>
</Group>
<Date>2017-03-25</Date>
</Section>
<Date>2017-03-25</Date>
</Data>
</Record>
预期输出
<Record>
<Data>
<ID>1234DFD57</ID>
<Group>
<abc-KD>243fds</abc-KD>
</Group>
<Section>
<ID>33-2311</ID>
<Date>2017-03-25</Date>
</Section>
<Date>2017-03-25</Date>
</Data>
</Record>
XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Section">
<xsl:copy>
<xsl:copy-of select="ID"/>
<xsl:if test="normalize-space(string(../Group)) = ''">
<xsl:copy-of select="Group"/>
</xsl:if>
<xsl:copy-of select="Date"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
您的意见非常感谢。
Regards,
谢谢!有效。你能解释一下如何使用模板吗?对不起,我仍然在学习基本部分,我无法理解你所做的解决方案。谢谢。 –
@AltheaVeronica请查看添加的说明。 –