【发布时间】:2018-10-05 12:19:32
【问题描述】:
我有以下 XML
<section>
<object>
<field name="First Source" />
<tableSection
propertyCount="1"
rowCount="1">
<tableProperty height="0"
width="570"
visible="true">
<property name="commit" />
</tableProperty>
<tableRow height="0"
width="0">
<tableCell value="Value First Source" />
</tableRow>
</tableSection>
</object>
<object>
<field name="Another Source" />
<tableSection
propertyCount="1"
rowCount="1">
<tableProperty height="0"
width="570"
visible="true">
<property name="commit" />
</tableProperty>
<tableRow height="0"
width="0">
<tableCell value="Invalid Value" />
</tableRow>
</tableSection>
</object>
</section>
并且有一个如下的xslt
<xsl:template match="tableRow">
<xsl:variable name="rowNodePosition">
<xsl:value-of select="position()"/>
</xsl:variable>
<tr allowDblCl="true" valign="top" height="50px">
<td>
<b>Row:</b>
<xsl:value-of select="$rowNodePosition"/>
<br/>
<xsl:for-each select="tableCell" >
<xsl:variable name="currPosition">
<xsl:value-of select="position()"/>
</xsl:variable>
<xsl:if test="@value != ''">
<b>
<xsl:value-of select="../../tableProperty[position() = $currPosition]/property/@name"/>: </b>
<xsl:value-of select="@value"/>
<br/>
</xsl:if>
</xsl:for-each>
</td>
</tr>
<tr>
<td colspan="4" height="15px"> </td>
</tr>
</xsl:template>
这将获得所有的 'tablRow'。但是我需要排除字段名称='Another Source'的tableRows,即如果对象节点具有名称为“Another Source”的'field',则排除节点tableSection的tableRow
【问题讨论】:
-
你想递归地应用模板。创建一个只匹配你想要的对象的模板,然后告诉它应用模板来匹配 tableRows。这样 tableRow 模板不会触发那些你不想要的。