IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Access Discussion :

Access VBA XML XSL Transform


Sujet :

VBA Access

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    69
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 69
    Par défaut Access VBA XML XSL Transform
    Bonjour,

    j'extrais de ma base access les données pour envoyer aux adhérents par courriel des informations concernant leur participation au covoiturage.

    il faut envoyer un courriel personnalisé à chaque adhérent et je n'ai pas trouvé la façon de faire avec le publipostage.

    le résultat recherché est fourni par la pièce jointe courriel_PECHE_79.txt

    l'extraction depuis la base se fait a l'aide d'une macro VBA et de la librairie Microsoft XML 6.0 .
    le résultat de cette extraction est un fichier xml (courriel_PECHE_79.xml) suivant le schéma xsd (indemnites.xsd)

    pour obtenir le résultat je souhaite utiliser une transformation xslt suivant la feuille de style indemnites_courriel_text.xsl

    sur internet j'ai trouvé deux méthodes pour faire cette transformation :

    Application.transform

    et

    l'utilisation de la méthode tramsforme de l'objet MSXML2.DOMDocument60 ?

    mais je n'arrive pas à les faire fonctionner.

    la première me donne un résultat, mais le fichier obtenu est incorrect (Courriel_VEZO_36.png) à rapprocher de l'encodage du fichier correct fourni par courriel_PECHE_79.png
    j'ai tenté d'utiliser un MXXMLWriter60 mais sans succès.


    la seconde m'indique un caractère non compris dans le jeu de caractères stipuler pour la transformation


    Merci pour vos réponses
    Gilbert Pêche



    ps le code des macros

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
     
    Sub transform_application()
    Dim result As New MSXML2.DOMDocument60
     
    'initialisation des variables
    Dim strPathGP, strPathGV, strPathxslt, strPathResultatGP, strPathResultatGV, strPathResultatGPgp, strPathResultatGVgp As String
    Dim stylesheet As New MSXML2.DOMDocument60
     
     
     
     
        strPathGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.xml"
     
        strPathxslt = "E:\Users\gilbert\marchipontain\ressource\indemnites_courriel_text.xsl"
        strPathResultatGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.txt"
        strPathResultatGVgp = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.gp"
     
     
        'l'opération se fait en 1 ligne
       ' Application.TransformXML strPath, strPathxslt, strPathResultat
     
     
     
        'oXmlDoc.transformNodeToObject stylesheet, result
        'result.
        Application.TransformXML strPathGV, strPathxslt, strPathResultatGVgp
        Dim iFileNo As Integer
        iFileNo = FreeFile
        result.Load strPathResultatGVgp
     
     
        Dim wrt As New MXXMLWriter60
        wrt.byteOrderMark = False
        wrt.omitXMLDeclaration = True
        wrt.Encoding = "Windows-1252"
        wrt.indent = False
    ' Now pass the DOM through the SAX handler, and it will call the writer
     
    Dim rdr As New SAXXMLReader60
        Set rdr.contentHandler = wrt
        Set rdr.dtdHandler = wrt
        Set rdr.errorHandler = wrt
        rdr.putProperty "http://xml.org/sax/properties/lexical-handler", wrt
        rdr.putProperty "http://xml.org/sax/properties/declaration-handler", wrt
     
    ' Now pass the DOM through the SAX handler, and it will call the writer
      rdr.parse result
     
     
     
    ' Let the writer do its thing
     
        Open strPathResultatGV For Output As #iFileNo
        Print #iFileNo, wrt.output
        Close #iFileNo
       ' result.Save strPathResultat
        Set rdr = Nothing
        Set wrt = Nothing
    End Sub
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    Sub transform_xmldoc()
    Dim result As New MSXML2.DOMDocument60
    Dim oXmlDoc As New MSXML2.DOMDocument60
    Dim stylesheet As New MSXML2.DOMDocument60
     
    Dim oerr As Error
    Dim strPathGP, strPathGV, strPathxslt, strPathResultatGP, strPathResultatGV, strPathResultatGPgp, strPathResultatGVgp As String
        strPathGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.xml"
     
        strPathxslt = "E:\Users\gilbert\marchipontain\ressource\indemnites_courriel_text.xsl"
        strPathResultatGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.txt"
     
        oXmlDoc.Load strPathGV
        stylesheet.Load "E:\Users\gilbert\marchipontain\ressource\indemnites_courriel_text.xsl"
     
        If stylesheet.parseError.errorCode <> 0 Then
            Set oerr = stylesheet.parseError
            MsgBox oerr.Description
        End If
        If oXmlDoc.parseError.errorCode <> 0 Then
            Set oerr = oXmlDoc.parseError
            MsgBox oerr.Description
        End If
        oXmlDoc.transformNodeToObject stylesheet, result
        result.Save strPathResultatGV
           Set stylesheet = Nothing
        Set oXmlDoc = Nothing
        Set result = Nothing
     
     
    End Sub
    Images attachées Images attachées   
    Fichiers attachés Fichiers attachés

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XML][XSL][FOP] transformation xml avec fop
    Par Le Marlou dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 05/12/2003, 16h58
  2. [XML/XSL] Transformation Excel
    Par Tyler Durden dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 27/11/2003, 21h00
  3. XML/XSL vers HTML: comment transformer les linefeed en <B
    Par AlainM dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 18/11/2003, 12h30
  4. Transformation xml + xsl -> HTML via PHP
    Par petit-ourson dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 19/10/2003, 22h42
  5. Pd de transformation XML/XSL sur un windows 2000 server US
    Par Sylvain Leray dans le forum XMLRAD
    Réponses: 3
    Dernier message: 24/03/2003, 11h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo