Skip to content

Instantly share code, notes, and snippets.

@michaelkeevildown
Last active January 14, 2019 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelkeevildown/7564c7434d0389ae3b0029b2ea51b6ff to your computer and use it in GitHub Desktop.
Save michaelkeevildown/7564c7434d0389ae3b0029b2ea51b6ff to your computer and use it in GitHub Desktop.
XSLT Example

Input XML:

<root>
    <id>trans-123</id>
    <transactions>
        <transaction>
            <sku>123</sku>
            <price currency="GBP">100<price>
        </transaction>
        <transaction>
            <sku>456</sku>
            <price currency="HKD">850<price>
        </transaction>
    </transactions>
</root>

Output:

{
    "elements" : [
        {
            "key": "/root/id",
            "value": "trans-123"
        },
        {
            "key": "/root/transactions/transaction/sku",
            "value": "123",
            "attributes" : [
                {
                    "parent": "transaction",
                    "position": 1
                }
            ]
        },
        {
            "key": "/root/transactions/transaction/price",
            "value": "100",
            "attributes" : [
                {
                    "parent": "transaction",
                    "position": 1
                },
                {
                    "parent":"price",
                    "name": "currency",
                    "value": "GBP"
                }
            ]
        },
        {
            "key": "/root/transactions/transaction/sku",
            "value": "456",
            "attributes" : [
                {
                    "parent": "transaction",
                    "position": 2
                }
            ]
        },
        {
            "key": "/root/transactions/transaction/price",
            "value": "850",
            "attributes" : [
                {
                    "parent": "transaction",
                    "position": 2
                },
                {
                    "parent":"price",
                    "name": "currency",
                    "value": "HKD"
                }
            ]
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment