0

I found this similar question for converting XML to CSV, which describes a generic XSLT for converting to CSV without knowing the exact XML structure

XML to CSV Using XSLT

Assuming the structure is not nested, and I just want essentially key-value pairs inside a root object, is it possible to create a similar XSLT that instead converts to JSON? If so, how?

For example XML

<POSTrans>
    <POSDocNo>INV1200004K89</POSDocNo>
    <Invoice_Exchange>Invoice</Invoice_Exchange>
    <POSDocDate>02/11/2018</POSDocDate>
    <POSDocTime>08:06:26 AM</POSDocTime>
    <OriginalInvoiceNo></OriginalInvoiceNo>
    <StoreNo>12</StoreNo>
    <IncrementIDNo>PRD0000003JW</IncrementIDNo>
    <BatchNumber>14080487</BatchNumber>
    <Medical_Recreational>Recreational</Medical_Recreational>
    <RFIDNo>1A400031266EDF4000100487</RFIDNo>
    <UOM>G</UOM>
    <GrossAmount>11.9500</GrossAmount>
    <DiscountAmount>2.9875</DiscountAmount>
    <TaxAmount>2.0614</TaxAmount>
    <Qty>1.0000</Qty>
    <UnitPrice>11.9500</UnitPrice>
    <PricingGrade>Value Flower</PricingGrade>
    <TotalLines>2</TotalLines>
    <LineNo>1</LineNo>
</POSTrans>

paul
  • 1,132
  • 11
  • 12
  • How would the JSON representation of an XHTML document look like, how one of an XSLT stylesheet or an SVG document? Do you expect there to be a generic stylesheet handling all such kind of documents? Or do you have a certain XML format and a certain JSON representation in mind? – Martin Honnen Mar 22 '18 at 21:10
  • 1
    Same question was asked here: https://stackoverflow.com/questions/44590783/xslt-generic-to-convert-xml-file-to-json but I can't close as a duplicate because that question wasn't answered, for reasons that are clear in the comments. – Michael Kay Mar 23 '18 at 00:32
  • Yes, that is my same question, I did not find it but thank you for finding it for me @MichaelKay – paul Mar 23 '18 at 14:27

0 Answers0