如何从XSLT中的XML中的递归内部节点获取数据

问题描述 投票:0回答:2

我试图获取具有相同名称数据的Inner Recursive节点。下面是我的示例XML,我需要格式输出

**

RegistrationIncludedProduct-43756.regPackagingHierarchyList-43767.regChildPackagingHierarchyList-43765.regChildPackagingHierarchyList-43763.regChildPackagingHierarchyList-43760

**

<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>30</stockKeepingUnit>
      <stockKeepingUnitStatus>Approved</stockKeepingUnitStatus>
      <nationalTradeItemNumber>098098</nationalTradeItemNumber>
      <registrationId>REG-00000023</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>a94c1128-b145-402b-a139-3bbe44cb04eb</uuid>
        <dateFormat>yyyy-MM-dd H:mm:ss</dateFormat>
        <generatedTimeStamp>2019-04-04 10:36:10</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>43756</recordId>
            <registration>
              <Registration>
                <dataState>C</dataState>
                <recordId>43750</recordId>
                <registrationUID>REG-00000023</registrationUID>
              </Registration>
            </registration>
          </RegistrationIncludedProduct>
        </regIncludedProduct>
        <regPackagingHierarchyList>
          <RegistrationPackagingHierarchy>
            <recordId>43767</recordId>
            <regChildPackagingHierarchyList></regChildPackagingHierarchyList>
            <regParentPackagingHierarchy>
              <RegistrationPackagingHierarchy>
                <recordId>43765</recordId>
                <regParentPackagingHierarchy>
                  <RegistrationPackagingHierarchy>
                    <recordId>43763</recordId>
                    <regParentPackagingHierarchy>
                      <RegistrationPackagingHierarchy>
                        <recordId>43760</recordId>
                      </RegistrationPackagingHierarchy>
                    </regParentPackagingHierarchy>
                  </RegistrationPackagingHierarchy>
                </regParentPackagingHierarchy>
              </RegistrationPackagingHierarchy>
            </regParentPackagingHierarchy>
            <regPkgHierarchyDataCarrierList></regPkgHierarchyDataCarrierList>
            <regErpCodesList></regErpCodesList>
          </RegistrationPackagingHierarchy>
        </regPackagingHierarchyList>
      </RegistrationPackaging>
    </agl_result>
  </LSRIMSData>
</agConnectXML>
xml xslt xslt-1.0 xslt-2.0 wso2esb
2个回答
0
投票

我尝试使用您给定的代码重现您的输出。这会产生您想要的输出:

<xsl:template match="regIncludedProduct">
    <fo:block>
        <xsl:call-template name="getContext"/> <!-- This is the first text in the numbering so we do not need the preceding '.' -->
        <xsl:text>-</xsl:text>
        <xsl:value-of select="RegistrationIncludedProduct/recordId"/>
        <xsl:apply-templates select="following-sibling::regPackagingHierarchyList[1]//recordId"/> 
        <!-- Based on your xml you can choose beween following:: and following-sibling:: , there is also the possibility to not only take the first following occurence. If you want to archive this just delete the [1] -->
    </fo:block>
</xsl:template>

<xsl:template match="recordId">
    <xsl:text>.</xsl:text>
    <xsl:call-template name="getContext"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="."/> <!-- '.' takes the text of the current context/node you are in, which is recordId -->
</xsl:template>

<xsl:template name="getContext">
    <xsl:choose>
        <xsl:when test="self::regIncludedProduct">RegistrationIncludedProduct</xsl:when>
        <xsl:when test="ancestor::regParentPackagingHierarchy">regChildPackagingHierarchyList</xsl:when>
        <xsl:when test="ancestor::regPackagingHierarchyList">regPackagingHierarchyList</xsl:when>
    </xsl:choose>
</xsl:template>

<xsl:template match="/">
    <xsl:apply-templates select="//regIncludedProduct"/>
</xsl:template>

如果您有任何问题,请随时问他们。 :)


0
投票
According to @Christian Mosz
Try:-
  <xsl:template match="@*|node()">
  <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="regPackagingHierarchyList">
  <xsl:value-of select="//following::regPackagingHierarchyList[1]//recordId"/>
  </xsl:template>
热门问题
推荐问题
最新问题