MS Access XLST要求

时间:2015-09-11 15:13:12

标签: xml xslt ms-access-2010

我已经回顾了几个不同的查询,我只是无法让转换工作,我有一个暗示,这是由于缺少相同名称副标题的唯一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 Notepad来验证我的数据,但根本没有成功。

希望我已经足够好地解释了这个问题。

提前致谢。

1 个答案:

答案 0 :(得分:0)

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>