我想使用計數器遞增和遞減XSLT中的值。我能夠使用Apache Xalan實現這一點,但現在我想用Saxon實現相同的功能。使用Saxon,增加或減少XSLT中的全局變量
我對Xalan的XSLT腳本是這樣的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:result="http://www.example.com/results"
extension-element-prefixes="result">
<lxslt:component prefix="result" functions="incr dcr">
<lxslt:script lang="javascript">
var count = 0;
function incr() {
count++;
return count;
}
function dcr() {
count--;
return count;
}
</lxslt:script>
</lxslt:component>
<xsl:template match="/">
a)<xsl:value-of select="result:incr()"/>
b)<xsl:value-of select="result:incr()"/>
c)<xsl:value-of select="result:dcr()"/>
</xsl:template>
</xsl:stylesheet>
預期成果是:
a)1
b)2
c)1
------------------------- my use case using saxon -------------------
This is my sample data.xml file. I want to transform this to html file.
<entity>
<record>10</record>
<record>15</record>
<record>19</record>
<record>7</record>
<record>4</record>
<record>14</record>
<record>24</record>
<entity>
I want to implement a counter for line-number and want to increment the counter and print the line-number
my expected outputs:
case 1: If record values > 14, then my output should have line-number with value as.
line-num value
1 15
2 19
3 24
case 2 : If record values < 14, then my output should have line-number with value as.
line-num value
1 10
2 7
3 4
My other use case :
<entity>
<record>10</record>
<record>15</record>
<record>19</record>
<record>7</record>
<record>20</record>
<record>14</record>
<record>24</record>
<entity>
<record>30</record>
<record>3</record>
</entity>
</entity>
<entity>
<record>5</record>
<record>17</record>
<record>19</record>
<record>6</record>
<record>70</record>
<record>9</record>
<record>35</record>
<entity>
<record>15</record>
<record>2</record>
</entity>
</entity>
This is my other use case, first <entity> record value > 15 and in second <entity> record value < 10, and my <entity> can grow bigger where i have to show only some record based on condition.
line-num value
1 19
2 20
3 24
4 30
5 5
6 6
7 2
謝謝你的精神。 –
我昨天經歷了撒克遜文檔,能夠想出它並嘗試了我的示例。 –
「希望我們可以展示純粹的XSLT 2.0解決方案,而不是使用可分配的變量」,我希望控制計數器,以便用任何整數值遞增/遞減。 –