很抱歉这个菜鸟问题,我已经通过添加不是很优雅的空模板已经解决了这个问题,但是有人可以帮助我理解为什么我一直在输出中看到另一个'level'的值吗?
这是我的xml外观:
<root>
<offers>
<theme>
<type>theme1</type>
<name>...</name>
<slug>...</slug>
<description>...</description>
<total>32</total>
<url_title>...</url_title>
<url_anchor>...</url_anchor>
<url>...</url>
<offers>
<row>
<offer>
<name>travel</type>
<id>68232</id>
</theme>
<theme>
<type>theme2</type>
<name>...</name>
<slug>...</slug>
<description>...</description>
<total>32</total>
<url_title>...</url_title>
<url_anchor>...</url_anchor>
<url>...</url>
<offers>
<row>
<offer>
<name>clowns</type>
<id>222</id>
</theme>
</offers>
</root>
每个主题仅包含1个报价。我想同时显示主题/报价/行/报价中的报价,因此我使用了:
<xsl:template match="root/offers">
<xsl:apply-templates select="theme[position() mod 2 = 1]" mode="row" />
</xsl:template>
<xsl:template match="theme" mode="row">
<xsl:apply-templates select="offers/row/offer/." mode="offer1" />
<xsl:apply-templates select="following-sibling::theme[1]" mode="offer2" />
</xls:template>
<xsl:template match="*" mode="offer1">
=== This one showed the offer correctly
</template>
<xsl:template match="offer" mode="offer2">
=== This one kept showing the 'type', 'name' 'slug'
=== values from the theme node,
=== even though I didn't ask for them
</xsl:template>
我只是通过添加空模板来解决它,就像这样:
<xsl:template match="theme/type" mode="offer2"/>
<xsl:template match="theme/name" mode="offer2"/>
<xsl:template match="theme/slug" mode="offer2"/>
我只想了解我哪里出错了。我一直对同级语法不满意(那里不能使用'.'...),我需要在'theme'级别使用mod 2 = 1,因为每个主题仅包含一个提议。