【发布时间】:2021-09-06 11:09:04
【问题描述】:
我正在尝试根据参数有条件地删除节点。
示例文件:
<A>
<B>
<C>Student Node</C>
<C>Teacher Node</C>
</B>
</A>
输出文件:
参数=1
<A>
<B>
<C>Student Node</C>
</B>
</A>
参数=0
<A>
<B>
<C>Teacher Node</C>
</B>
</A>
这是我当前的 xslt 尝试:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="preview_type"></xsl:param>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:choose>
<xsl:when test="$preview_type = 0">
<xsl:template match="/A/B/C[text()='Student Node']"/>
</xsl:when>
<xsl:otherwise>
<xsl:template match="/A/B/C[text()='Teacher Node']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:stylesheet>
目前,我收到错误:
SystemId Unknown; Line #13; Column #15; xsl:choose is not allowed in this position in the stylesheet!
任何帮助都会很棒。我想我缺少一些关于模板/Xslt 的概念。
GC_
【问题讨论】:
-
参数看起来更像是你想选择由位置指定的元素,而不是删除它。其背后的逻辑是什么?
-
@zx485 对于条件1,我想删除标签,对于条件2,我想删除另一个标签。
-
@zx485 我正在使用空模板删除元素。空模板标签中没有副本。
-
但是您的问题包括三种状态:
0) 在 xsl:when 和1和2中的param示例中。 -
zx485 抱歉,我知道那会怎样。这两个状态是 0 和 1。