计算子节点

时间:2013-08-30 23:58:42

标签: xslt-2.0

我有低于有效负载,我必须在<Document>下计算子元素的数量。 例如:

<Document>
  <Class>D</Class>`enter code here`
  <ClassDescription>Drawings</ClassDescription>
  <ClientDocumentNumber>12345</ClientDocumentNumber>
<Document>

计数为3。

有效负载如下。检查此代码。

<?xml version="1.0" encoding="UTF-8"?>
<InputVariable>
    <part  name="payload">
        <ProjectMessage>
            <ConversationId>E53252F709653493E0401E0A13916A2E</ConversationId>
            <SourceApplicationId>Convero</SourceApplicationId>
            <Operation>INS DOC</Operation>
            <ModifiedByUserEmail>daviD.Woo@xyz.com</ModifiedByUserEmail>
            <Project>
                <Id>100020</Id>
                <DocumentList>
                    <Document>
                        <Class>D</Class>
                        <ClassDescription>Drawings</ClassDescription>
                        <ClientDocumentNumber>12345</ClientDocumentNumber>
                        <ClientRevisionNumber>2.0</ClientRevisionNumber>
                        <Discipline>141</Discipline>
                        <DisciplineDescription>ACN</DisciplineDescription>
                        <Facility>24</Facility>
                        <Number>100020-24-140-SKT-0002</Number>
                        <OSROriginator>086238</OSROriginator>
                        <Revision>2.0</Revision>
                        <RevisionDate>2013-02-11T00:00:00Z</RevisionDate>
                        <Status>A</Status>
                        <StatusDescription>Active</StatusDescription>
                        <SupplierDocumentNumber>523570.000</SupplierDocumentNumber>
                        <SupplierRevisionNumber>CCC</SupplierRevisionNumber>
                        <Title>Test for FileNet</Title>
                        <Type>NA</Type>
                        <TypeDescription>NA</TypeDescription>
                    </Document>
                </DocumentList>
            </Project>
        </ProjectMessage>
    </part>
</InputVariable>

1 个答案:

答案 0 :(得分:0)

<xsl:template match="Document">
  <xsl:value-of select="count(*)"/>
</xsl:template>

是匹配Document元素并计算子元素的模板。