2014-12-08 231 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