Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74474 > unrolled thread

xslt with python

Started byvarun bhatnagar <varun292006@gmail.com>
First post2014-07-15 10:10 +0200
Last post2014-07-15 15:58 +0200
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  xslt with python varun bhatnagar <varun292006@gmail.com> - 2014-07-15 10:10 +0200
    Re: xslt with python Tim <jtim.arnold@gmail.com> - 2014-07-15 06:12 -0700
      Re: xslt with python varun bhatnagar <varun292006@gmail.com> - 2014-07-15 15:58 +0200

#74474 — xslt with python

Fromvarun bhatnagar <varun292006@gmail.com>
Date2014-07-15 10:10 +0200
Subjectxslt with python
Message-ID<mailman.11833.1405415553.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I am trying to merge two xmls using xslt in python but the content of first
xml is not getting copied. The rules written in xsl file created are
correct because if I am executing it without python (directly from eclipse
as I have xslt plugin installed) it is getting merged fine. Can anybody
help me? I am pasting my code snippet below:

*import lxml.etree as ET*

*dom = ET.parse(r'test_file_2.xml')*
*xslt = ET.parse(r'TestMergeRules.xsl')*
*transform = ET.XSLT(xslt)*
*print transform*
*newdom = transform(dom)*
*print(ET.tostring(newdom, pretty_print=True))*

I am opening other xml file (test_file_1.xml) in xsl file using
"document()" function.
Once this code is executed I can see only the content of test_file_2.xml.
Am I doing something wrong? Is there any other way to do this because my
xslt rules are working fine without python.

Thanks,
BR,
Varun

[toc] | [next] | [standalone]


#74482

FromTim <jtim.arnold@gmail.com>
Date2014-07-15 06:12 -0700
Message-ID<ddfb29d5-8119-4eae-917f-6fca4930e7e1@googlegroups.com>
In reply to#74474
On Tuesday, July 15, 2014 4:10:57 AM UTC-4, varun bhatnagar wrote:
> I am trying to merge two xmls using xslt in python but the content of first xml is not getting copied. The rules written in xsl file created are correct because if I am executing it without python (directly from eclipse as I have xslt plugin installed) it is getting merged fine. Can anybody help me? I am pasting my code snippet below:
> 
> import lxml.etree as ET
> dom = ET.parse(r'test_file_2.xml')
> xslt = ET.parse(r'TestMergeRules.xsl')
> transform = ET.XSLT(xslt)
> print transform
> 
> newdom = transform(dom)
> print(ET.tostring(newdom, pretty_print=True))
>
> I am opening other xml file (test_file_1.xml) in xsl file using "document()" function.
> 
> Once this code is executed I can see only the content of test_file_2.xml.
> Am I doing something wrong? Is there any other way to do this because my xslt rules are working fine without python.
> 
Hi BR,
Your code looks very close but not exactly equal to the tutorial here:
http://lxml.de/xpathxslt.html#xslt

Can you try the example on that page and report the results?
Plus your platform, python version and lxml details as described here:
http://lxml.de/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do

thanks,
--Tim Arnold

[toc] | [prev] | [next] | [standalone]


#74485

Fromvarun bhatnagar <varun292006@gmail.com>
Date2014-07-15 15:58 +0200
Message-ID<mailman.11837.1405432747.18130.python-list@python.org>
In reply to#74482

[Multipart message — attachments visible in raw view] — view raw

Hi Tim,

Thanks a lot for the reply. I think I got the root cause of the problem.
Before merging I am creating one dummy xml file on the fly and I am copying
the content of first xml into that. This dummy file I am mentioning in xsl
file and the URI is changing because of which it is not getting merged.
I have to see how can I resolve the URI problem.


//Varun


On Tue, Jul 15, 2014 at 3:12 PM, Tim <jtim.arnold@gmail.com> wrote:

> On Tuesday, July 15, 2014 4:10:57 AM UTC-4, varun bhatnagar wrote:
> > I am trying to merge two xmls using xslt in python but the content of
> first xml is not getting copied. The rules written in xsl file created are
> correct because if I am executing it without python (directly from eclipse
> as I have xslt plugin installed) it is getting merged fine. Can anybody
> help me? I am pasting my code snippet below:
> >
> > import lxml.etree as ET
> > dom = ET.parse(r'test_file_2.xml')
> > xslt = ET.parse(r'TestMergeRules.xsl')
> > transform = ET.XSLT(xslt)
> > print transform
> >
> > newdom = transform(dom)
> > print(ET.tostring(newdom, pretty_print=True))
> >
> > I am opening other xml file (test_file_1.xml) in xsl file using
> "document()" function.
> >
> > Once this code is executed I can see only the content of test_file_2.xml.
> > Am I doing something wrong? Is there any other way to do this because my
> xslt rules are working fine without python.
> >
> Hi BR,
> Your code looks very close but not exactly equal to the tutorial here:
> http://lxml.de/xpathxslt.html#xslt
>
> Can you try the example on that page and report the results?
> Plus your platform, python version and lxml details as described here:
> http://lxml.de/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do
>
> thanks,
> --Tim Arnold
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web