Importing xml with nested nodes into Access (and needing to transform the xml into a 'flat' structure with xsl)

梦想与她 提交于 2020-01-15 09:52:56

问题


Desperately trying and failing to import some data into Access that comprises of various nested nodes that on import are being put into separate tables when I only desire to have one.

I just would like to have the Activity table with all the data in the nested nodes to be in this parent table.

I've tried adjusting some code from a previous similar question but my attempt appears hopeless as it is not even pulling any information from the 'Activity' table, however it has created the 'AttID' field in the 'CstActivity' table that I suppose I could eventually get to the point in order to do a join / link across tables. Only problem is it didn't actually populate this with the relevant ids!

But ideally, I would just like to transform the data so that the import just includes everything in the nested nodes in the relevant lines on the 'Activity' node.

xml to be imported:


<?xml version="1.0" encoding="utf-8"?>
<ns:HCDSExtract xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819">
  <ns:MessageHeader>
    <ns:OrgSubmittingID>RRK</ns:OrgSubmittingID>
    <ns:FinYr>FY2018-19</ns:FinYr>
    <ns:PeriodStartDate>2018-05-01</ns:PeriodStartDate>
    <ns:PeriodEndDate>2018-05-31</ns:PeriodEndDate>
    <ns:CreateDateTime>2018-03-28T18:25:04</ns:CreateDateTime>
    <ns:FeedType>OP</ns:FeedType>
    <ns:NoOfActivityRecords>10</ns:NoOfActivityRecords>
    <ns:TotalCosts>100.000</ns:TotalCosts>
  </ns:MessageHeader>
  <ns:MessageBody>
    <ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503898066984</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>01</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503898066984</ns:AttID>
      <ns:HRG>WF01A</ns:HRG>
      <ns:AppDte>2018-05-11T14:29:00</ns:AppDte>
      <ns:Tfc>172</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true" />
      <ns:PatOrgId xsi:nil="true" />
      <ns:CstActivity>
        <ns:ActCstID>OUT001</ns:ActCstID>
        <ns:ActCnt>1440</ns:ActCnt>
        <ns:Resource>
          <ns:ResCstID>CPF005</ns:ResCstID>
          <ns:TotCst>10.00000000</ns:TotCst>
        </ns:Resource>
      </ns:CstActivity>
    </ns:Activity>
</ns:MessageBody>
</ns:HCDSExtract>

my xsl file:

<xsl:stylesheet version="1.0" xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <dataroot>
            <xsl:apply-templates select="@*|node()"/>
        </dataroot>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="ns:Activity">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>

    <xsl:template match="ns:CstActivity">
        <ns:CstActivity>
            <ns:AttID><xsl:value-of select="../ns:AttID"/></ns:AttID>
            <xsl:apply-templates select="@*|node()"/>
        </ns:CstActivity>
    </xsl:template>

</xsl:stylesheet>

Any help will be hugely appreciated. Thank you in advance.

edit:

My new xsl is below:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819">

      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>

<xsl:template match="ns:CstActivity"><xsl:apply-templates /></xsl:template>



<xsl:template match="ns:Resource"><xsl:apply-templates /></xsl:template>



    </xsl:stylesheet>

So my latest xsl gives an output like:

    <ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897890061</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>02</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897890061</ns:AttID>
      <ns:HRG>WF01A</ns:HRG>
      <ns:AppDte>2018-05-28T17:14:00</ns:AppDte>
      <ns:Tfc>306</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true"/>
      <ns:PatOrgId xsi:nil="true"/>

        <ns:ActCstID>DIM007</ns:ActCstID>
        <ns:ActCnt>3</ns:ActCnt>

          <ns:ResCstID>CPF002</ns:ResCstID>
          <ns:TotCst>10.00000000</ns:TotCst>

Which is good, however for the section

        <ns:ActCstID>DIM007</ns:ActCstID>
        <ns:ActCnt>3</ns:ActCnt>

          <ns:ResCstID>CPF002</ns:ResCstID>
          <ns:TotCst>10.00000000</ns:TotCst>

There may be many of these 4 bits of information for each entry in the parent node....and I would like each relevant record in the parent node to be repeated for each of the different child nodes. I hope that makes sense.

So many desired output xml would be:

   <ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897890061</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>02</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897890061</ns:AttID>
      <ns:HRG>WF01A</ns:HRG>
      <ns:AppDte>2018-05-28T17:14:00</ns:AppDte>
      <ns:Tfc>306</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true"/>
      <ns:PatOrgId xsi:nil="true"/>
      <ns:ActCstID>DIM007</ns:ActCstID>
      <ns:ActCnt>3</ns:ActCnt>
      <ns:ResCstID>CPF002</ns:ResCstID>
      <ns:TotCst>10.00000000</ns:TotCst>
 </ns:Activity>
<ns:Activity>
 <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897890061</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>02</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897890061</ns:AttID>
      <ns:HRG>WF01A</ns:HRG>
      <ns:AppDte>2018-05-28T17:14:00</ns:AppDte>
      <ns:Tfc>306</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true"/>
      <ns:PatOrgId xsi:nil="true"/>
      <ns:ActCstID>MID127</ns:ActCstID>
      <ns:ActCnt>2</ns:ActCnt>
      <ns:ResCstID>CPD060</ns:ResCstID>
      <ns:TotCst>12.05000000</ns:TotCst>
</ns:Activity>

Any help much appreciated!

Latest edit to outline hoped for output. I am sorry I probably didn't give a very good example input xml to work a solution from but hopefully the input / output xml explains what I'm looking for more clearly.

input xml:

 <ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897986301</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>01</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897986301</ns:AttID>
      <ns:HRG>WF01B</ns:HRG>
      <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
      <ns:Tfc>191</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true" />
      <ns:PatOrgId xsi:nil="true" />
      <ns:CstActivity>
        <ns:ActCstID>OUT001</ns:ActCstID>
        <ns:ActCnt>1</ns:ActCnt>
        <ns:Resource>
          <ns:ResCstID>CPF002</ns:ResCstID>
          <ns:TotCst>0.01711470</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF004</ns:ResCstID>
          <ns:TotCst>0.00005506</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF011</ns:ResCstID>
          <ns:TotCst>0.12799014</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF022</ns:ResCstID>
          <ns:TotCst>0.00622135</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF023</ns:ResCstID>
          <ns:TotCst>6.55181258</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF024</ns:ResCstID>
          <ns:TotCst>0.08211900</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF027</ns:ResCstID>
          <ns:TotCst>0.04333875</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CSC004</ns:ResCstID>
          <ns:TotCst>18.95493831</ns:TotCst>
        </ns:Resource>
      </ns:CstActivity>
      <ns:CstActivity>
        <ns:ActCstID>SUP001</ns:ActCstID>
        <ns:ActCnt>1</ns:ActCnt>
        <ns:Resource>
          <ns:ResCstID>CPF002</ns:ResCstID>
          <ns:TotCst>0.00000124</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF011</ns:ResCstID>
          <ns:TotCst>0.00000148</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF022</ns:ResCstID>
          <ns:TotCst>0.00002230</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF023</ns:ResCstID>
          <ns:TotCst>-0.00000221</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CPF024</ns:ResCstID>
          <ns:TotCst>0.00017128</ns:TotCst>
        </ns:Resource>
        <ns:Resource>
          <ns:ResCstID>CSC004</ns:ResCstID>
          <ns:TotCst>0.16603542</ns:TotCst>

hoped for output xml:

<ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897986301</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>01</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897986301</ns:AttID>
      <ns:HRG>WF01B</ns:HRG>
      <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
      <ns:Tfc>191</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true"/>
      <ns:PatOrgId xsi:nil="true"/>
      <ns:ActCstID>OUT001</ns:ActCstID>
      <ns:ActCnt>1</ns:ActCnt>
      <ns:ResCstID>CPF002</ns:ResCstID>
      <ns:TotCst>0.01711470</ns:TotCst>
</ns:Activity>
<ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897986301</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>01</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897986301</ns:AttID>
      <ns:HRG>WF01B</ns:HRG>
      <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
      <ns:Tfc>191</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true"/>
      <ns:PatOrgId xsi:nil="true"/>
      <ns:ActCstID>THR001</ns:ActCstID>
      <ns:ActCnt>2</ns:ActCnt>
      <ns:ResCstID>CPF004</ns:ResCstID>
      <ns:TotCst>0.00005506</ns:TotCst>
</ns:Activity>        
    <ns:Activity>
      <ns:OrgId>RRK</ns:OrgId>
      <ns:CDSID>503897986301</ns:CDSID>
      <ns:NHSNo>1111111111</ns:NHSNo>
      <ns:NhsSt>01</ns:NhsSt>
      <ns:Postcd>RD15 2AD</ns:Postcd>
      <ns:DoB>1967-04-01</ns:DoB>
      <ns:Gendr>1</ns:Gendr>
      <ns:Pod>NCL</ns:Pod>
      <ns:AttID>503897986301</ns:AttID>
      <ns:HRG>WF01B</ns:HRG>
      <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
      <ns:Tfc>191</ns:Tfc>
      <ns:ConCode>C0000000</ns:ConCode>
      <ns:PathId xsi:nil="true"/>
      <ns:PatOrgId xsi:nil="true"/>
      <ns:ActCstID>SUP001</ns:ActCstID>
      <ns:ActCnt>1</ns:ActCnt>
      <ns:ResCstID>CPF002</ns:ResCstID>
      <ns:TotCst>0.00000124</ns:TotCst>
</ns:Activity>

So essentially, for every variation of the fields below, the old parent node is brought in so we have many lines for each CDSID and not just one.

  <ns:ActCstID>SUP001</ns:ActCstID>
  <ns:ActCnt>1</ns:ActCnt>
  <ns:ResCstID>CPF002</ns:ResCstID>
  <ns:TotCst>0.00000124</ns:TotCst>

Thank you again for any of your help.


回答1:


Here you have an example for flattening some hierarchy like:

<countries>
    <country>
        <name>USA</name>
        <state>Alabama</state>
        <state>Colorado</state>
    </country>
</countries>

This stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="countries">
        <states>
            <xsl:apply-templates select="country/state" mode="uprise"/>
        </states>
    </xsl:template>

    <xsl:template match="state"/>

    <xsl:template match="state" mode="uprise">
        <xsl:copy>
            <name>
                <xsl:value-of select="."/>
            </name>
            <xsl:apply-templates select=".."/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="country/name">
        <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>

Output:

<states>
   <state>
      <name>Alabama</name>
      <country>USA</country>
   </state>
   <state>
      <name>Colorado</name>
      <country>USA</country>
   </state>
</states>

Do note: for flattening you target the leaves and then produce output going up the hierarchy. In this case I'm using the overriding indentity template pattern, thus there is a mode to process the leaf and another mode (default) to stop the process in order to not produce an infinite loop.

EDIT: Because you seems to have troubles following this logic, I will show you an stylesheet just with the names changed to match your input sample (also corrected to be well formed).

This input:

<ns:HCDSExtract xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819">
   <ns:MessageHeader>
      <ns:OrgSubmittingID>RRK</ns:OrgSubmittingID>
      <ns:FinYr>FY2018-19</ns:FinYr>
      <ns:PeriodStartDate>2018-05-01</ns:PeriodStartDate>
      <ns:PeriodEndDate>2018-05-31</ns:PeriodEndDate>
      <ns:CreateDateTime>2018-03-28T18:25:04</ns:CreateDateTime>
      <ns:FeedType>OP</ns:FeedType>
      <ns:NoOfActivityRecords>10</ns:NoOfActivityRecords>
      <ns:TotalCosts>100.000</ns:TotalCosts>
   </ns:MessageHeader>
   <ns:MessageBody>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:CstActivity>
            <ns:ActCstID>OUT001</ns:ActCstID>
            <ns:ActCnt>1</ns:ActCnt>
            <ns:Resource>
               <ns:ResCstID>CPF002</ns:ResCstID>
               <ns:TotCst>0.01711470</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF004</ns:ResCstID>
               <ns:TotCst>0.00005506</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF011</ns:ResCstID>
               <ns:TotCst>0.12799014</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF022</ns:ResCstID>
               <ns:TotCst>0.00622135</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF023</ns:ResCstID>
               <ns:TotCst>6.55181258</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF024</ns:ResCstID>
               <ns:TotCst>0.08211900</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF027</ns:ResCstID>
               <ns:TotCst>0.04333875</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CSC004</ns:ResCstID>
               <ns:TotCst>18.95493831</ns:TotCst>
            </ns:Resource>
         </ns:CstActivity>
         <ns:CstActivity>
            <ns:ActCstID>SUP001</ns:ActCstID>
            <ns:ActCnt>1</ns:ActCnt>
            <ns:Resource>
               <ns:ResCstID>CPF002</ns:ResCstID>
               <ns:TotCst>0.00000124</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF011</ns:ResCstID>
               <ns:TotCst>0.00000148</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF022</ns:ResCstID>
               <ns:TotCst>0.00002230</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF023</ns:ResCstID>
               <ns:TotCst>-0.00000221</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CPF024</ns:ResCstID>
               <ns:TotCst>0.00017128</ns:TotCst>
            </ns:Resource>
            <ns:Resource>
               <ns:ResCstID>CSC004</ns:ResCstID>
               <ns:TotCst>0.16603542</ns:TotCst>
            </ns:Resource>
         </ns:CstActivity>
      </ns:Activity>
   </ns:MessageBody>
</ns:HCDSExtract>

With this stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
        xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819">
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>

        <xsl:template match="ns:MessageBody">
            <xsl:copy>
                <xsl:apply-templates
                     select="ns:Activity/ns:CstActivity/ns:Resource" mode="uprise"/>
            </xsl:copy>
        </xsl:template>

        <xsl:template match="ns:Resource|ns:CstActivity|ns:MessageHeader"/>

        <xsl:template match="ns:Resource" mode="uprise">
            <ns:Activity>
                <xsl:apply-templates select="../../*|../*"/>
                <xsl:apply-templates/>            
            </ns:Activity>
        </xsl:template>
    </xsl:stylesheet>

Output:

<ns:HCDSExtract xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819">
   <ns:MessageBody>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF002</ns:ResCstID>
         <ns:TotCst>0.01711470</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF004</ns:ResCstID>
         <ns:TotCst>0.00005506</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF011</ns:ResCstID>
         <ns:TotCst>0.12799014</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF022</ns:ResCstID>
         <ns:TotCst>0.00622135</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF023</ns:ResCstID>
         <ns:TotCst>6.55181258</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF024</ns:ResCstID>
         <ns:TotCst>0.08211900</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF027</ns:ResCstID>
         <ns:TotCst>0.04333875</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>OUT001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CSC004</ns:ResCstID>
         <ns:TotCst>18.95493831</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>SUP001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF002</ns:ResCstID>
         <ns:TotCst>0.00000124</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>SUP001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF011</ns:ResCstID>
         <ns:TotCst>0.00000148</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>SUP001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF022</ns:ResCstID>
         <ns:TotCst>0.00002230</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>SUP001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF023</ns:ResCstID>
         <ns:TotCst>-0.00000221</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>SUP001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CPF024</ns:ResCstID>
         <ns:TotCst>0.00017128</ns:TotCst>
      </ns:Activity>
      <ns:Activity>
         <ns:OrgId>RRK</ns:OrgId>
         <ns:CDSID>503897986301</ns:CDSID>
         <ns:NHSNo>1111111111</ns:NHSNo>
         <ns:NhsSt>01</ns:NhsSt>
         <ns:Postcd>RD15 2AD</ns:Postcd>
         <ns:DoB>1967-04-01</ns:DoB>
         <ns:Gendr>1</ns:Gendr>
         <ns:Pod>NCL</ns:Pod>
         <ns:AttID>503897986301</ns:AttID>
         <ns:HRG>WF01B</ns:HRG>
         <ns:AppDte>2018-05-02T10:19:00</ns:AppDte>
         <ns:Tfc>191</ns:Tfc>
         <ns:ConCode>C0000000</ns:ConCode>
         <ns:PathId xsi:nil="true"/>
         <ns:PatOrgId xsi:nil="true"/>
         <ns:ActCstID>SUP001</ns:ActCstID>
         <ns:ActCnt>1</ns:ActCnt>
         <ns:ResCstID>CSC004</ns:ResCstID>
         <ns:TotCst>0.16603542</ns:TotCst>
      </ns:Activity>
   </ns:MessageBody>
</ns:HCDSExtract>

Check it here




回答2:


Consider this revised XSLT, that walks down the tree (as opposed to identity transform) to only parse ns:Activity node and its children and grandchildren. Additionally, script avoids re-writing their nodes since in MS Access's ImportXML, each distinct nested element becomes its own table.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:ns="http://Improvement.nhs.uk/HealthcareCostingDataSet/v03-1819" 
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/ns:HCDSExtract">
        <dataroot>
            <xsl:apply-templates select="ns:MessageBody"/>
        </dataroot>
    </xsl:template>

    <xsl:template match="ns:MessageBody">
        <xsl:apply-templates select="ns:Activity"/>
    </xsl:template>

    <xsl:template match="ns:Activity">
        <xsl:copy>
            <xsl:copy-of select="*[not(*)]"/>
            <xsl:copy-of select="*/*[not(*)]"/>
            <xsl:copy-of select="*/*/*"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

XSLT demo



来源:https://stackoverflow.com/questions/57494402/importing-xml-with-nested-nodes-into-access-and-needing-to-transform-the-xml-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!