A
A
Artem2014-02-25 20:14:08
JSON
Artem, 2014-02-25 20:14:08

How to retrofit an XSL template to transform xml2Json?

Hello! I have an xml to json conversion template.
There is 1 problem: you need to modernize it so that all xml tags during the "pass" to json become lowercase (only tag names, the values ​​themselves must be in the original).
Link to xsl
I don't understand xsl well. If someone is in the subject, save.
For example like this:
XML:

<Widget>
<VALUE>Dfdfdf</VALUE>
</wiDget>

Json:
"widget" : {"value" : "Dfdfdf" }
As you can see from the example, the tag names have changed to lowercase, but the case has been preserved in the value.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2014-02-25
@Properrr

Add to the beginning of the template:

<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

In the places where the node name is received, add a call to the translate() function:
...
<xsl:variable name="nName" select="translate(name(.), $uppercase, $smallcase)"/>
...

XSL 2.0 provides the lower-case() function for this purpose.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question