问题描述
||
假设我有一个看起来像这样的XML文件:
<a id=\"x\">
<b>
<b>
<a id=\"y\">
<b>
<c />
</b>
</a>
</b>
<c>
<a id=\"z\">
<b>
<c />
</b>
</a>
</c>
</b>
</a>
经过许多小时的工作,我终于得到了它,以使\“ a \”,\“ b \”和\“ c \”模板正确地递归。我可能剩下的那个是我需要a/@id
的值才能在b
和c
中使用。但是,当到达内部a
时,我还需要能够重置该值。 (也就是说,在a#x > b > b > a#y > b > c
中,我需要值''y \',但是在a#x > b > b
中,我需要值''x \'。换句话说,我需要最古老的value1'值。)
b
元素可以无限次嵌套的事实使问题变得复杂,因此,做simply9ѭ之类的事情并不简单。
由于似乎不能使用变量或参数来解决此问题,因此我认为可以接受的解决方法是自动将ѭ10向下传递给每个子元素。但是,我无法找到使用xsl:attribute
进行此操作的方法,因为这似乎总是会修改输出树,而不是输入树或当前正在处理的树。
有小费吗?
解决方法
你不能只做十二英镑吗?
<xsl:template match=\"a\">
...
<xsl:apply-templates match=\"*\" />
</xsl:template>
<xsl:template match=\"b\">
<xsl:variable name=\"id\" select=\"ancestor::a[first()]/@id\" />
...
<xsl:apply-templates match=\"*\" />
</xsl:template>
<xsl:template match=\"b\">
<xsl:variable name=\"id\" select=\"ancestor::a[first()]/@id\" />
...
<xsl:apply-templates match=\"*\" />
</xsl:template>