Subject: [xsl] Re: creating multiple xml documents from one large xml document From: "Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 26 May 2023 21:55:22 -0000 |
With the Python lxml library you can get pretty close to what you can do with XSLT, although you do not have the power of XPath 2 or 3 in the current implementation. But you can certainly do basic XPath selection of elements. And of course you dont have all the power of apply-templates (unless you implemented your own Python version of template matching, which could be interesting but not trivial to do sufficiently completely). While I love XSLT, I am also coming to appreciate the value of Python as a language that is accessible to more people than XSLT is and that can be adapted to a subset of problems where I would otherwise use XSLT, namely data extraction or light transformation. I would still use XSLT for more involved document-to-document transformations. (Another aspect of Python for XML that Im finding interesting is the similarity between using lxml and using XQuery update: both make it about as easy as it can be to do update-in-place of documents using a more familiar procedural programming style. Beyond that, the style of program you get in Python matches closely to the equivalent in XQuery. Im finding it easier to get people not familiar with XML transformation to understand were modifying this element to turn X into Y than were transforming from X to Y through this system of template matches when the problem at hand is relatively simple.) So if your current environment is Python and it would otherwise be useful to stay there, I would suggest you can do what you want without having to abandon Python. Or you could call Saxon from a Python program as a command-line call then consume the result using lxml and continue on your Pythonic way. Obviously applying Python to XML is outside the scope of this list, but I dont know where else you could ask a how can I achieve this XML result in Python using XPath and lxml? unless its ChatGPT. Cheers, E. _____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.com<https://www.servicenow.com> LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow> From: LEGAULT, PHILLIP plegault@xxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Friday, May 26, 2023 at 2:57 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: [xsl] creating multiple xml documents from one large xml document [External Email] ________________________________ Im working with salesforce soap xml, 3 namespaces, I am splitting them currently with python. I need a simpler way and hoping I can do it with XML. Each case has this as the beginning node and element of course with the end tag, for each case I want everything in between in each file. If there is no case node skip <records xsi:type="sf:CaseNote_GCC__c"> Insert child node with date it was created There are 2 child nodes I want to name the file with <sf:Id>xxxxxxxxxxxxxx</sf:Id> and <sf:CaseNumber>xxxxxxxxxxx</sf:CaseNumber> Thanks for your help. Phil Legault XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3453418> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] creating multiple xml doc, Martin Honnen martin | Thread | Re: [xsl] Re: creating multiple xml, Martin Honnen martin |
Re: [xsl] creating multiple xml doc, Martin Honnen martin | Date | Re: [xsl] Re: creating multiple xml, Martin Honnen martin |
Month |