【问题标题】:How can I get the Index position using XSLT如何使用 XSLT 获取索引位置
【发布时间】:2014-12-08 09:24:22
【问题描述】:
<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>

我想仅根据条件 row type="data" 知道其中包含“a”的列的位置

【问题讨论】:

  • 以 XML 格式发布您的 XSLT 以及所需的输出。
  • 你(认为你)为什么需要这个?
  • w3.org/1999/XSL/Transform"> 在 if 条件下我想根据行类型进行过滤
  • 请不要在 cmets 中发布代码 - 而是编辑您的问题。

标签: xml xslt xpath xquery xsd-validation


【解决方案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>

【讨论】:

  • @AnshuKumar,欢迎您,在以后的帖子中,放置您的输入 xml,尝试 XSLT,并要求输出。
猜你喜欢
  • 2020-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
  • 2012-04-15
  • 1970-01-01
相关资源
最近更新 更多