2014-12-08 236 views
1

XML:的XPath位置文本(或属性)是等于值

<row type="header"> 
<column>href</column> 
<column>other</column> 
</row> 
<row type="data"> 
<column>a</column> 
<column>b</column> 
</row> 

XSLT:(我确保我行[@类型=“数据”] /在模板列下面)

<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> 

如何获得文本()等于href的列位置?如果更容易,我可以给列的值'href'一个属性。例如:<column type='link'>href</column>

编辑:
我尝试以下,但没有工作
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

简单的答案是,testt是一个变量,所以你需要使用$前缀以供参考

<xsl:value-of select="../../row[@type='header']/column[position() = $testt]" /> 

当然,这是选择'header'行的列,你已经知道它包含“href”。也许你只需要这样做?

<xsl:value-of select="../column[position() = $testt]" /> 
+0

哇,这是一个愚蠢的错误。非常感谢。 – Grafit 2014-12-08 09:17:46