- From: Michael Kay <mike@saxonica.com>
- Date: Sat, 9 Jan 2021 19:54:33 +0000
- To: Dimitre Novatchev <dnovatchev@gmail.com>, public-xslt-40@w3.org
- Message-Id: <3B925C77-757E-4C58-A5CC-D8166F996292@saxonica.com>
Let's do a use case: converting
<hiistory>
<created by="Michael Kay" on="2016-12-19"/>
<modified by="Michael Kay" on="2017-08-10" change="more precise result assertion"/>
<modified by="Michael Kay" on="2019-12-02" change="Test wrongly assumed that document order was predictable.'"/>
</history>
to JSON:
[
{ "event": "created",
"by" : "Michael Kay",
"on" : "2016-12-19" },
{"event" : "modified:
"by" : "Michael Kay",
"on" : "2017-08-10",
"change" : "more precise result assertion" },
{"event" : "modified:
"by" : "Michael Kay",
"on" : "2019-12-02",
"change" : "est wrongly assumed that document order was predictable." }
]
I want to do this using template rules. Something like this:
<xsl:output method="json"/>
<xsl:template match="history">
<xsl:array>
<xsl:apply-templates/>
</xsl:array>
</xsl:template>
<xsl:template match="history/*">
<xsl:array-member>
<xsl:map>
<xsl:map-entry key="'event'" select="local-name()"/>
<xsl:apply-templates select="@*"/>
</xsl:map>
</xsl:array-member>
</xsl:template>
<xsl:template match="@*">
<xsl:map-entry key="local-name()" select="."/>
</xsl:template>
How would you want to write this?
Michael Kay
Saxonica
>
Received on Saturday, 9 January 2021 19:54:49 UTC