I have data like:




I want to transform it into:


How can I do this?

Was it helpful?


Use a computed element constructor to generate an element with the lower-case value of the text nodes for each of the td elements.

A computed element constructor creates an element node, allowing both the name and the content of the node to be computed.

For the sake of the example, assuming that your XML is in a file called foo.xml, you could do something like this:

for $name in doc('foo.xml')//td/text()
return element {lower-case($name)} {''}

to produce this:

<?xml version="1.0" encoding="UTF-8"?>

You could also evaluate the lower-case() function as part of the XPATH expression instead of the element constructor, like this:

for $name in doc('foo.xml')//td/text()/lower-case(.)
return element {$name} {''}


return <doc>{
for $d in $doc/element()/text()
return element{fn:lower-case($d)} {}}</doc>  

where $doc stores the Xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow