Skip to content

How to generate an XML element with attributes and an array value from a map #2293

Closed Answered by gorgenarrows
gorgenarrows asked this question in Q&A

You must be logged in to vote

And, I'm an idiot. I just needed to let "figure" be an array and the correct XML was output. The following works:

. *? load(strenv(update))
| {
	"div": {
		"+@class" : "gallery",
		"figure": map(.caption as $caption
			| {
			"+@class": "gallery__item",
			"a": {
				"+@href": .image,
				"+@data-size": .data-size,
				"img": {
					"+@src": .thumbnail,
					"+@alt": .alt,
					"+@width": .width,
					"+@height": .height
				}
			}
			} | ((select($caption != "") | .figcaption) = $caption)
		)
	}
}

I'm closing this.

Replies: 1 comment

You must be logged in to vote
0 replies
Answer selected by gorgenarrows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant