如何在xslt中累加position()函数的值
我有这个 xml 文件
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="file:/dev/null" iosp="lasp.tss.iosp.ValueGeneratorIOSP" start="0" increment="1">
<attribute name="title" value="Vector time series"/>
<dimension name="time" length="100"/>
<variable name="time" shape="time" type="double">
<attribute name="units" type="String" value="seconds since 1970-01-01T00:00"/>
</variable>
<group name="Vector" tsdsType="Structure" shape="time">
<variable name="x" shape="time" type="double"/>
<variable name="y" shape="time" type="double"/>
<variable name="z" shape="time" type="double"/>
</group>
</netcdf>
,我需要 xslt 文件,它给出这样的输出
1.time
2.Vector
,它们是两个标签的名称属性:变量和组。目前我有这样的代码
<xsl:for-each select="document($path)//*[local-name()='variable']">
<xsl:if test="string-length( @*[local-name()='name'] ) >1">
<li>
<xsl:value-of select="position()"/>
<xsl:value-of select="@*[local-name()='name']"/>
</li>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="document($path)//*[local-name()='group']">
<li>
<xsl:value-of select="position()"/>
<xsl:value-of select="@*[local-name()='name']"/>
</li>
</xsl:for-each>
,它会给我
1.time
1.Vector
那么我如何通过这个position()函数达到我的目标,或者有其他更好的方法在XSLT中做到这一点?预先非常感谢。
I have this xml file
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="file:/dev/null" iosp="lasp.tss.iosp.ValueGeneratorIOSP" start="0" increment="1">
<attribute name="title" value="Vector time series"/>
<dimension name="time" length="100"/>
<variable name="time" shape="time" type="double">
<attribute name="units" type="String" value="seconds since 1970-01-01T00:00"/>
</variable>
<group name="Vector" tsdsType="Structure" shape="time">
<variable name="x" shape="time" type="double"/>
<variable name="y" shape="time" type="double"/>
<variable name="z" shape="time" type="double"/>
</group>
</netcdf>
and I need the xslt file which gives the output like this
1.time
2.Vector
which are the name attribute of two tags: variable and group. Currently I have the code like this
<xsl:for-each select="document($path)//*[local-name()='variable']">
<xsl:if test="string-length( @*[local-name()='name'] ) >1">
<li>
<xsl:value-of select="position()"/>
<xsl:value-of select="@*[local-name()='name']"/>
</li>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="document($path)//*[local-name()='group']">
<li>
<xsl:value-of select="position()"/>
<xsl:value-of select="@*[local-name()='name']"/>
</li>
</xsl:for-each>
and it will give me
1.time
1.Vector
So how can I reach my goal by this position() function or there are any other better way to do this in XSLT? Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
position()
但它应该在同一重复指令内使用。声明带有前缀x
的命名空间并使用:此外,我会使用
xsl:number
,例如:还可以考虑在样式表中声明默认命名空间,以便您可以摆脱
local-name()
测试。You can use
position()
but it should be used inside the same repetition instruction. Declare the namespace with prefix sayx
and use:Moreover I would use
xsl:number
like:Consider also to declare the default namespace in your stylesheet so that you can get rid of
local-name()
tests.