如何在XSLT中计算Loop内部的父级的所有子节点

时间:2019-04-04 15:35:16

标签: xml xslt xslt-1.0 xslt-2.0 xslt-3.0

需要为以下XML计算所有子级别中父节点的子代数和父子代数。

  

如何查找<regPackagingHierarchyList>岁以下儿童的数量   节点为<recordId>

我尝试遵循代码

<xsl:for-each select="LSRIMSData/agl_result/RegistrationPackaging/regPackagingHierarchyList/RegistrationPackagingHierarchy[recordId/text()!='']">
    <xsl:value-of select="count(child::regParentPackagingHierarchy/RegistrationPackagingHierarchy/recordId/node())"></xsl:value-of>
</xsl:for-each>

源XML:

<agConnectXML>
  <SourceData>
    <SKUIDOut noNamespaceSchemaLocation="file:///c:/Users/BODDUAV1/OneDrive%20-%20Novartis%20Pharma%20AG/Avanthi/NovaRIM/Documents/SHAPE/stockKeepingUnit.xsd" schemaVersion="1.0">
      <SystemMessageHeader>
        <CreationDateTime>2002-10-10T12:00:00-05:00</CreationDateTime>
        <SenderID>sandoz</SenderID>
        <BusinessSystemID>SHAPE-P34-SKU</BusinessSystemID>
        <MessageID>678678-2389789-4893947-473946</MessageID>
      </SystemMessageHeader>
      <stockKeepingUnit>40</stockKeepingUnit>
      <stockKeepingUnitStatus>Approved</stockKeepingUnitStatus>
      <nationalTradeItemNumber>098098</nationalTradeItemNumber>
      <registrationId>REG-00000026</registrationId>
      <finishedDosageFormId>FDF-002</finishedDosageFormId>
      <activeSusbstanceId>6437</activeSusbstanceId>
      <tenant>sandoz</tenant>
    </SKUIDOut>
  </SourceData>
  <LSRIMSData>
    <agl_result>
      <agl_service_headers>
        <serviceId>CustgetRegPackDetails</serviceId>
        <messageProducer>agidmp</messageProducer>
        <internalVersion>12077</internalVersion>
        <uuid>5670bf06-4f0a-4f0f-ab93-2d2ad99a7384</uuid>
        <dateFormat>yyyy-MM-dd H:mm:ss</dateFormat>
        <generatedTimeStamp>2019-04-04 20:02:09</generatedTimeStamp>
        <user>system</user>
      </agl_service_headers>
      <agl_pagination_details>
        <start>0</start>
        <limit>10</limit>
        <totalRecordsCount>1</totalRecordsCount>
      </agl_pagination_details>
      <RegistrationPackaging>
        <productPackaging>
          <ProductPackaging>
            <packagingItemName>FDF-002</packagingItemName>
          </ProductPackaging>
        </productPackaging>
        <regIncludedProduct>
          <RegistrationIncludedProduct>
            <recordId>43893</recordId>
            <registration>
              <Registration>
                <dataState>C</dataState>
                <recordId>43887</recordId>
                <registrationUID>REG-00000026</registrationUID>
              </Registration>
            </registration>
          </RegistrationIncludedProduct>
        </regIncludedProduct>
        <regPackagingHierarchyList>
          <RegistrationPackagingHierarchy>
            <recordId>43914</recordId>
            <regParentPackagingHierarchy>
              <RegistrationPackagingHierarchy>
                <recordId>43912</recordId>
              </RegistrationPackagingHierarchy>
            </regParentPackagingHierarchy>
            <regPkgHierarchyDataCarrierList></regPkgHierarchyDataCarrierList>
            <regErpCodesList></regErpCodesList>
          </RegistrationPackagingHierarchy>
          <RegistrationPackagingHierarchy>
            <recordId>43916</recordId>
            <regParentPackagingHierarchy>
              <RegistrationPackagingHierarchy>
                <recordId>43914</recordId>
                <regParentPackagingHierarchy>
                  <RegistrationPackagingHierarchy>
                    <recordId>43912</recordId>
                    <regParentPackagingHierarchy>
                      <RegistrationPackagingHierarchy>
                        <recordId>43916</recordId>
                      </RegistrationPackagingHierarchy>
                    </regParentPackagingHierarchy>
                  </RegistrationPackagingHierarchy>
                </regParentPackagingHierarchy>
              </RegistrationPackagingHierarchy>
            </regParentPackagingHierarchy>
            <regPkgHierarchyDataCarrierList></regPkgHierarchyDataCarrierList>
            <regErpCodesList></regErpCodesList>
          </RegistrationPackagingHierarchy>
        </regPackagingHierarchyList>
      </RegistrationPackaging>
    </agl_result>
  </LSRIMSData>
</agConnectXML>

预期结果将采用以下格式

  

Count(regParentPackagingHierarchy / RegistrationPackagingHierarchy / RecordIds)   = 1计数(regParentPackagingHierarchy / RegistrationPackagingHierarchy / RecordIds)   = 3

1 个答案:

答案 0 :(得分:0)

  

如何查找import random from threading import Thread from multiprocessing import Process size = 10000000 # Number of random numbers to add to list threads = 2 # Number of threads to create my_list = [] for i in xrange(0,threads): my_list.append([]) def func(count, mylist): for i in range(count): mylist.append(random.random()) def multithreaded(): jobs = [] for i in xrange(0, threads): thread = Thread(target=func,args=(size,my_list[i])) jobs.append(thread) # Start the threads for j in jobs: j.start() # Ensure all of the threads have finished for j in jobs: j.join() def simple(): for i in xrange(0, threads): func(size,my_list[i]) def multiprocessed(): processes = [] for i in xrange(0, threads): p = Process(target=func,args=(size,my_list[i])) processes.append(p) # Start the processes for p in processes: p.start() # Ensure all processes have finished execution for p in processes: p.join() if __name__ == "__main__": multithreaded() #simple() #multiprocessed() 岁以下儿童的数量   节点为<regPackagingHierarchyList>

您的输入中只有<recordId>的一个实例。假设您的意思是regPackagingHierarchyList,并且您实际上想计算每个RegistrationPackagingHierarchy的所有后代(不仅是孩子)的所有recordId元素,您可以尝试一些方法喜欢:

RegistrationPackagingHierarchy

给出您的XML示例,结果将是:

<xsl:template match="/agConnectXML">
    <xsl:for-each select="LSRIMSData/agl_result/RegistrationPackaging/regPackagingHierarchyList/RegistrationPackagingHierarchy">
        <xsl:text>count = </xsl:text>
        <xsl:value-of select="count(descendant::recordId)"/>
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
</xsl:template>