我需要使用XSL 1.0转换xml表。该表有两个块thead
和tbody
,它们都有0 ... n row
。行有条目(也称为单元格)。
<Table>
<Tgroup cols="6">
<Thead>
<Row>
<Entry> this is row 1 </Entry>
<Entry> this is row 1</Entry>
</Row>
</Thead>
<Tbody>
<Row>
<Entry> this is row 2 </Entry>
<Entry> this is row 2 </Entry>
</Row>
<Row>
<Entry> this is row 3 </Entry>
<Entry> this is row 3 </Entry>
</Row>
</Tbody>
</Tgroup>
</Table>
如何在entry
和tbody
上获取行索引(在转换thead
时)?
当我在tbody中计算行数时,它会忽略行中的行。不幸的是,如果有的话,我也必须计算它们。
这是我当前的模板,它不能满足我的需求:
<xsl:template match="Entry">
<!-- only counts inside the same ancestor, e.g. only rows in tbody -->
<xsl:number count="../../*[name()='Row']" from="*[self::*[name()='Tgroup']]"/>
</xsl:template>
(是的,我知道name()='Row'
不好,但原始的xsl使用节点名称的变量。)
答案 0 :(得分:1)
这是你需要的吗?
<xsl:number count="*[name()='Row']" level="any"/>
或许这样,如果你的XML实际上有名称空间(因为我不明白你的意思是说你的XSL使用节点名称的变量)
<xsl:number count="*[local-name()='Row']" level="any"/>
不同之处在于后者适用于您有名称空间前缀的情况,例如<my:Row>
编辑:在回复您的评论时,请尝试使用from
属性
<xsl:number count="*[local-name()='Row']" level="any" from="Table"/>