Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT1.0维护生成Id的子节点计数_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml XSLT1.0维护生成Id的子节点计数

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

我要计算特定重复父节点的子节点数。 我需要这个计数来维护转换后特定元素的id

下面是我使用的request.xml的格式

<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"/>