如何使用XSLT获取Index位置

时间:2014-12-08 09:24:23

标签: xml xslt xpath xquery xsd-validation

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

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
    <xsl:for-each select="row">
        <xsl:if test="">
            <xsl:value-of select="column"/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

我想知道包含&#34; a&#34;的列的位置。在它基于条件行类型=&#34;数据&#34;仅

1 个答案:

答案 0 :(得分:1)

试试这个:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="root">
    <xsl:for-each select="row[@type='data']/column">
        <xsl:if test="contains(., 'a')">
            <xsl:value-of select="position()"/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>