【问题标题】:How to fetch the Data from Recursive Inner Nodes from XML in XSLT如何在 XSLT 中从 XML 中的递归内部节点获取数据
【发布时间】:2019-04-04 07:34:44
【问题描述】:

我正在尝试获取具有相同名称数据的内部递归节点。 下面是我的示例 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>

【问题讨论】:

  • 到目前为止您尝试过什么?你能分享你所做的努力吗?谢谢。
  • 是否总是跟在 标签后面?您可能只在 上使用匹配项,在其中应用“following::regPackagingHierarchyList[1]//recordId”
  • 谢谢@ChristianMosz。我尝试使用模板匹配。但没有任何明确的想法。但问题是这样的。我想从这个 XML 中输出 Level1、Level2、Level3、Level4、Level5 ...... XML 结构。是一个内部递归结构。我对此知之甚少。能否请您帮忙编写详细的代码。
  • &lt;regPackagingHierarchyList&gt; &lt;RegistrationPackagingHierarchy&gt; &lt;recordId&gt;level5&lt;/recordId&gt; &lt;regParentPackagingHierarchy&gt; &lt;RegistrationPackagingHierarchy&gt; &lt;recordId&gt;level4&lt;/recordId&gt; &lt;regParentPackagingHierarchy&gt; &lt;RegistrationPackagingHierarchy&gt; &lt;recordId&gt;level3&lt;/recordId&gt; &lt;/RegistrationPackagingHierarchy&gt; &lt;/regParentPackagingHierarchy&gt; &lt;/RegistrationPackagingHierarchy&gt; &lt;/regParentPackagingHierarchy&gt; &lt;/RegistrationPackagingHierarchy&gt; &lt;/regPackagingHierarchyList&gt;
  • @ChristianMosz 由于评论的限制,我发送了单独的代码。假设仍然存在多个级别,并且在所有级别中都存在 recordid。需要通过将recordId与逗号连接来输出

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


【解决方案1】:

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

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

如果您有任何问题,请随时提出。 :)

【讨论】:

    【解决方案2】:
    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>
    

    【讨论】:

      猜你喜欢
      • 2014-10-06
      • 1970-01-01
      • 2011-01-19
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多