问题
XML:
<row type="header">
<column>href</column>
<column>other</column>
</row>
<row type="data">
<column>a</column>
<column>b</column>
</row>
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>
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>
Edit:
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>
回答1:
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]" />
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]" />
来源:https://stackoverflow.com/questions/27354417/xpath-position-where-text-or-attribute-is-equal-to-value