2

I must transform xml2xml. I have an XSLT file that works fine with other XML files and I adapt it to the followed file (just a test file) :

<?xml version="1.0" encoding="UTF-8"?>
<invoice:request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:invoice="http://www.xmlData.ch/xmlInvoice/XSD" 
  xsi:schemaLocation="http://www.xmlData.ch/xmlInvoice/XSD 
  MDInvoiceRequest_400.xsd" role="production">

  <invoice:prolog>
    <invoice:package>Handy patients</invoice:package>
    <invoice:software>Handy patients</invoice:software>
    <invoice:validator>tarmedValidator100 ATL Module Copyright © by Suva &amp; santésuisse</invoice:validator>
  </invoice:prolog>

  <invoice:invoice invoice_id="23">
    <invoice:balance>
      <invoice:vat>0.00</invoice:vat>
    </invoice:balance>
    <invoice:detail>
      <invoice:services>
        <invoice:record_tarmed>Prestation médicale en l'absence du patient (y compris étude de dossier), par période de 5 min
        </invoice:record_tarmed>
        <invoice:record_tarmed>Rapport médical sur formulaire assurance-maladie, {AA}, {AM}/Rapport intermédiaire/Feuille annexe sur formulaire {AI}
        </invoice:record_tarmed>
       </invoice:services>
     </invoice:detail>
   </invoice:invoice>

and then XSLT file :

    <?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance">

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:template match="invoice:request">
    <xsl:copy>
      <xsl:for-each-group select="invoice:invoice " group-by="@invoice_id">
        <xsl:element name="Facture">
          <xsl:for-each select="current-group()">
            <xsl:element name="Package">
              <xsl:value-of select="../invoice:prolog/invoice:package"/>
            </xsl:element>
          </xsl:for-each>
        </xsl:element>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

 </xsl:stylesheet>

I have a warning : Impossible de transformer : Error at line 13, column 28: Namespace prefix xsl on value-of is not defined

what can I do ?

Sylvia Yenni
  • 53
  • 2
  • 7
  • 1
    You stylesheet is tagged `version="1.0"` but `xsl:for-each-group` requires XSLT 2.0. Does your processor support it? – michael.hor257k Aug 01 '17 at 15:39
  • thanks for yours propositions. I maked this two changes but the result is the same. what else can I do ? – Sylvia Yenni Aug 01 '17 at 16:20
  • **1.** The result is **not** the same. You should see a different error message, due to the fact that the `invoice:` prefix is undeclared. -- **2.** You did not answer my question: does your processor support XSLT 2.0? Changing the version on your stylesheet is irrelevant to this. – michael.hor257k Aug 01 '17 at 16:40
  • ok. I have tested with saxon and I have these errors : – Sylvia Yenni Aug 02 '17 at 08:19
  • ok. I have tested with saxon and I have these errors : XPST0081 : Namespace prefix 'invoice' has not been declared XPST0090 : attribute @name is not allowed on element but invoice prefix is used in xml file ? please, what must I do ? – Sylvia Yenni Aug 02 '17 at 08:25
  • You must tell us whether you can use XSLT 2.0 or not. By "use", I mean use in actual production - what you use for your own testing is irrelevant. – michael.hor257k Aug 02 '17 at 08:46
  • for production I use MSXML2.DOMDocument in Access – Sylvia Yenni Aug 02 '17 at 12:11
  • Well, then you cannot use XSLT 2.0 and you need to learn how to do grouping in XSLT 1.0 using the Muenchian method: http://www.jenitennison.com/xslt/grouping/muenchian.html -- You also need to learn how to handle elements that are in a namespace - see: https://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k Aug 02 '17 at 12:43

1 Answers1

1

Start by changing this:

xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance"

to:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

But you have numerous other issues that this correction will expose.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51