Xml XSLT1.0维护生成Id的子节点计数
我要计算特定重复父节点的子节点数。 我需要这个计数来维护转换后特定元素的id 下面是我使用的request.xml的格式Xml XSLT1.0维护生成Id的子节点计数,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我要计算特定重复父节点的子节点数。 我需要这个计数来维护转换后特定元素的id 下面是我使用的request.xml的格式 <Party><Notes><Notes><Party> <Party><Notes><Notes></Party> 转换后的xml应为: <Attachment id=1></Attachment> <Attachment id=2>&l
<Party><Notes><Notes><Party>
<Party><Notes><Notes></Party>
转换后的xml应为:
<Attachment id=1></Attachment>
<Attachment id=2></Attachment>
<Attachment id=3></Attachment>
<Attachment id=4></Attachment>
我尝试使用:
<xsl:value-of select="concat('Attachment',count(preceding-sibling::Notes))" />
但它没有给出正确的值。
任何指导都可以帮助我解决这个问题。您可以使用count(preference::Notes)+1
,但我更喜欢使用xsl:number
例如
XML(固定格式)
XSLT1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Notes">
<Attachment>
<xsl:attribute name="id">
<xsl:number level="any"/>
</xsl:attribute>
</Attachment>
</xsl:template>
</xsl:stylesheet>
输出
<Attachment id="1"/>
<Attachment id="2"/>
谢谢您的指导。这正是我需要的。@user2394566-不客气。请单击左侧的复选标记接受此答案。谢谢<代码>不是有效的XML。它需要引号
不是有效的XML。不清楚您有多少子节点。请更正它-只有你知道它应该是什么
<Attachment id="1"/>
<Attachment id="2"/>