英文:
New tag by position from xsl
问题
<xsl:template match="column">
<xsl:element name="column_{position() + count(../preceding-sibling::row/column)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
英文:
I have a slightly different question, comparing to this previous one:
<?xml version="1.0" encoding="UTF-8"?>
<importoTotaleCommissioni>
<row>
<column>5</column>
<column>6</column>
</row>
<row>
<column>5</column>
<column>6</column>
<column>7</column>
<column>8</column>
</row>
</importoTotaleCommissioni>
I have to create an output, by xsl, with tags named positionally, for example
<importoTotaleCommissioni>
<row>
<column_1>5</column_1>
<column_2>6</column_2>
</row>
<row>
<column_1>5</column_1>
<column_2>6</column_2>
<column_3>7</column_3>
<column_4>8</column_4>
</row>
</importoTotaleCommissioni>
The columns enumeration must restart at every row. I have tried using
<xsl:template match="column">
<xsl:element name="column_{position()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
... but it gives me wrong enumaration. How can I correct this?
答案1
得分: -1
可以使用此模板代替:
<xsl:template match="column">
<xsl:element name="column_{count(preceding-sibling::column)+1}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
英文:
You could use this template instead :
<xsl:template match="column">
<xsl:element name="column_{count(preceding-sibling::column)+1}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论