I am using XSLT to transform XML.
I am currently hard-coding each attribute name like so:
<xsl:for-each select="variable">
{
"name" : "<xsl:value-of select="@name" />",
"value" : "<xsl:value-of select="@value" />"
}
</xsl:for-each>
But this seems really messy. Is there a way to dynamically create the key value pairs from the attributes without having to hardcode each attribute name individually ? i.e. Above I have specified :
"name" : "<xsl:value-of select="@name" />"
Is there a way to change it so that I just use some variable in loop so it is like:
(pseudocode:)
<for each attribute in my element>
{
"attribute.name" : "attribute.value",
}
</xsl:for-each>
EDIT: Edited the question, so JSON is irrelevant to what I'm trying to do. Just trying to transform the name value pairs as described above, without hard coding.
<xsl:for-each select="@*">and use<xsl:value-of select="name()" />and<xsl:value-of select="." />. It's your funeral, you have been warned.