文本(或属性)等于值的 XPath 位置 [英] XPath position where text (or attribute) is equal to value
问题描述
XML:
<row type="header">
<column>href</column>
<column>other</column>
</row>
<row type="data">
<column>a</column>
<column>b</column>
</row>
XSLT:(我确保我在下面模板的行[@type='data']/列中)
XSLT:(I'm making sure I'm in row[@type='data']/column in the template below)
<xsl:template match="column" mode="panelTabsBody">
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="../../row[@type='header']/column[text()='href'][position()]" />
</xsl:attribute>
</a>
</td>
</xsl:template>
如何获取 text() 等于 href 的列位置?如果更容易,我可以为值为href"的列指定一个属性.示例:
How can I get the column position where the text() is equal to href? If it's easier, I can give the column with the value 'href' an attribute. Example: <column type='link'>href</column>
我尝试了以下方法,但这没有用
XSLT:
I tried the following, but this didnt work
XSLT:
<xsl:template match="column" mode="panelTabsBody">
<xsl:variable name="testt" select="count(../../row[@type='header']/column[text()='href']/preceding-sibling::column) + 1" />
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="../../row[@type='header']/column[position() = testt]" />
</xsl:attribute>
</a>
</td>
</xsl:template>
推荐答案
简单的答案是 testt
是一个变量,所以你需要使用一个 $
前缀来参考一下
The simple answer is that testt
is a variable, so you need to use a $
prefix to reference it
<xsl:value-of select="../../row[@type='header']/column[position() = $testt]" />
当然,这是为标题"行选择列,您已经知道该列包含href".也许你只需要这样做?
Of course, this is selecting the column for the 'header' row, which you already know contains "href". Perhaps you just need to do this?
<xsl:value-of select="../column[position() = $testt]" />
这篇关于文本(或属性)等于值的 XPath 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!