1

Many questions on this topic have been answered, but I can't seem to solve my problem by adapting them, so I'll have to ask again.

I have this XML file:

 <ARTICLE CREATION_DATETIME="2018-07-02T17:38:25.0330824+02:00" PROD_DATE="2018-07-02T00:00:00" VALID_DATE="2018-07-02T00:00:00" xmlns="http://www.hcisolutions.ch/index">
  <ART DT="2018-06-20T00:00:00+02:00">
    <PHAR>0103504</PHAR>
    <PHARMACODE>103504</PHARMACODE>
    <GTIN>7680379690281</GTIN>
    <ARTNO>103504</ARTNO>
    <GRPCD>M1</GRPCD>
    <CDSO1>03.00.00.00</CDSO1>
    <PRDNO>17437</PRDNO>
    [...goes on for miles...]
    <ARTPRI>
      <VDAT>2018-01-01T00:00:00+01:00</VDAT>
      <PTYP>PEXF</PTYP>
      <PRICE>10.55</PRICE>
    </ARTPRI>
  </ART>
  <ART> [...]

I'd like to add the PHARMACODE attribute to the ARTPRI subnode, so that I can link between the main ART table and the child ARTPRI table after import into Access.

Desired output:

      <ART DT="2018-06-20T00:00:00+02:00">
        <PHAR>0103504</PHAR>
        <PHARMACODE>103504</PHARMACODE>
        <GTIN>7680379690281</GTIN>
        <ARTNO>103504</ARTNO>
        <GRPCD>M1</GRPCD>
        <CDSO1>03.00.00.00</CDSO1>
        <PRDNO>17437</PRDNO>
        [...goes on for miles...]
        <ARTPRI>
          <PHARMACODE>103504</PHARMACODE>
          <VDAT>2018-01-01T00:00:00+01:00</VDAT>
          <PTYP>PEXF</PTYP>
          <PRICE>10.55</PRICE>
        </ARTPRI>
[...goes on for miles...]

Adapting the various answers on this topic I found, here's my actual XSL file, which doesn't do anything (as far as I can tell):

<?xml version="1.0" ?>
<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="ARTPRI">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:copy-of select="ancestor::ART/PHARMACODE"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

What's wrong with it?

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • Thank You @MartinHonnen for pointing me to the right answer (problemin namesapce). After a bit of fiddling and following Pavel Minaev advice on the use of my: in https://stackoverflow.com/questions/1344158/xslt-with-xml-source-that-has-a-default-namespace-set-to-xmlns, I was able to solve my problem. – Damien Cateau Jul 25 '18 at 13:13

0 Answers0