为什么我从另一个位置(xslt)看值?

问题描述 投票:0回答:2

很抱歉这个菜鸟问题,我已经通过添加不是很优雅的空模板已经解决了这个问题,但是有人可以帮助我理解为什么我一直在输出中看到另一个'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,因为每个主题仅包含一个提议。

xml xslt xslt-1.0
2个回答
1
投票
由于Built-in Template Rules而出现问题

0
投票
您已在此处https://www.w3.org/TR/1999/REC-xslt-19991116将此标记为XSLT 1.0版规范
© www.soinside.com 2019 - 2024. All rights reserved.