MS Access XLST 要求

MS Access XLST Requirement

我已经审查了几个关于此的不同查询,但我只是无法使转换工作,我有一种暗示,这是由于同名副标题缺少唯一 ID,但我不确定 (不是真正的开发者)。

我的XML是:

<MT_REQ_EXCEPTIONS>
<Header>
 <UserID>userid</UserID>
 <Password>password</Password>
 <Carrier>0000</Carrier>
 <Poster>00000000</Poster>
 <PostingDate>09092015</PostingDate>
 <OrderNumber>20150909</OrderNumber>
 <IntermediaryAccount/>
 <TransactionID>e592e236756a474daea7b9e0bbad369b</TransactionID>
 <SalesOrder>A00000000</SalesOrder>
 </Header>
<Detail>
 <IDType>40941700008493</IDType>
 <CodeType>404</CodeType>
 <CodeType2>DS3</CodeType2>
 <Field4>N</Field4>
 <Format/>
 <Discount/>
 <DifferentType/>
<Weights>
 <CodeType3>NAT</CodeType3>
 <NumberField>536</NumberField>
 <NumberField2>0</NumberField2>
 </Weights>
<Tracking>
 <ItemID/>
 </Tracking>
<CustomerData>
 <AccountID>V360284 </AccountID>
 <CustomerField1/>
 <CustomerField2/>
 <CustomerField3/>
 <CustomerField4/>
 <Numerical1/>
 <Numerical2/>
 </CustomerData>
 </Detail>
<Detail>
 <IDType>40941700008532</IDType>
 <CodeType>393</CodeType>
 <CodeType2>DS3</CodeType2>
 <Field4>N</Field4>
 <Format/>
 <Discount/>
 <DifferentType/>
<Weights>
 <CodeType3>NAT</CodeType3>
 <NumberField>536</NumberField>
 <NumberField2>0</NumberField2>
 </Weights>
<Tracking>
 <ItemID/>
 </Tracking>
<CustomerData>
 <AccountID>V360284 </AccountID>
 <CustomerField1/>
 <CustomerField2/>
 <CustomerField3/>
 <CustomerField4/>
 <Numerical1/>
 <Numerical2/>
 </CustomerData>
 </Detail>
<Trailer>
 <RecordCount>2</RecordCount>
 </Trailer>
 </MT_REQ_EXCEPTIONS>

我需要它看起来像:

<MT_REQ_EXCEPTIONS>
<Header>
 <UserID>userid</UserID>
 <Password>password</Password>
 <Carrier>0000</Carrier>
 <Poster>00000000</Poster>
 <PostingDate>09092015</PostingDate>
 <OrderNumber>20150909</OrderNumber>
 <IntermediaryAccount/>
 <TransactionID>e592e236756a474daea7b9e0bbad369b</TransactionID>
 <SalesOrder>A00000000</SalesOrder>
 </Header>
<Detail>
 <PostingDate>09092015</PostingDate>
 <IDType>40941700008493</IDType>
 <CodeType>404</CodeType>
 <CodeType2>DS3</CodeType2>
 <Field4>N</Field4>
 <Format/>
 <Discount/>
 <DifferentType/>
<Weights>
 <IDType>40941700008493</IDType>
 <CodeType3>NAT</CodeType3>
 <NumberField>536</NumberField>
 <NumberField2>0</NumberField2>
 </Weights>
<Tracking>
 <ItemID/>
 </Tracking>
<CustomerData>
 <IDType>40941700008493</IDType>
 <AccountID>V360284 </AccountID>
 <CustomerField1/>
 <CustomerField2/>
 <CustomerField3/>
 <CustomerField4/>
 <Numerical1/>
 <Numerical2/>
 </CustomerData>
 </Detail>
<Detail>
 <PostingDate>09092015</PostingDate>
 <IDType>40941700008532</IDType>
 <CodeType>393</CodeType>
 <CodeType2>DS3</CodeType2>
 <Field4>N</Field4>
 <Format/>
 <Discount/>
 <DifferentType/>
<Weights>
 <IDType>40941700008532</IDType>
 <CodeType3>NAT</CodeType3>
 <NumberField>536</NumberField>
 <NumberField2>0</NumberField2>
 </Weights>
<Tracking>
 <ItemID/>
 </Tracking>
<CustomerData>
 <IDType>40941700008532</IDType>
 <AccountID>V360284 </AccountID>
 <CustomerField1/>
 <CustomerField2/>
 <CustomerField3/>
 <CustomerField4/>
 <Numerical1/>
 <Numerical2/>
 </CustomerData>
 </Detail>
<Trailer>
 <RecordCount>2</RecordCount>
 </Trailer>
 </MT_REQ_EXCEPTIONS>

到目前为止,我一直在努力使用具有以下性质的 XLST 在“详细信息”字段中获取可用的 PostingDate:

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

  <xsl:template match="Header|Detail">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:copy-of select="ancestor::MT_REQ_EXCEPTIONS/Header/PostingDate"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

如果有任何关于如何解决这个问题的想法,那就太好了。我有一种感觉,我无法将 PostingDate 纳入细节是因为 Detail 没有任何索引或唯一性,并且将 IDType 纳入权重会出现同样的问题,作为权重,如果也是一个可以出现多次的字段。 我的理想目标是在 Access 本身中执行此操作,但我尝试使用 XML 记事本来验证我的数据,但完全没有成功。

希望我已经充分解释了这个问题。

提前致谢。

AFAICT,以下样式表生成预期的输出:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template match="Detail">
    <xsl:copy>
        <xsl:copy-of select="../Header/PostingDate"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

<xsl:template match="Weights | CustomerData">
    <xsl:copy>
        <xsl:copy-of select="../IDType"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>