Jump to content

converting attributes to child elements


marina

Recommended Posts

maybe something in this spirit:

<xsl:template match="marca"><marca><xsl:apply-templates/></marca></xsl:template><xsl:temlpate match="@href"><href><xsl:value-of select="."/></href></xsl:template>

Link to comment
Share on other sites

It doesn't work.It just works when I tried this:<xsl:template match="marca"><marca><xsl:element name="href"><xsl:value-of select="@href"/></xsl:element><xsl:apply-templates/></marca></xsl:template>But how can I simplify, if I want to transform all the attributes of a xml doc, into child elementes of the element that tey were attributes?

Link to comment
Share on other sites

It doesn't work.It just works when I tried this:<xsl:template match="marca"><marca><xsl:element name="href"><xsl:value-of select="@href"/></xsl:element><xsl:apply-templates/></marca></xsl:template>But how can I simplify, if I want to transform all the attributes of a xml doc, into child elementes of the element that tey were attributes?

Perhaps if you generalize your solution by adding more wildcards, like this:
<xsl:template match="//*"><xsl:element name="local-name(.)"><xsl:for-each select="@*"><xsl:element name="local-name(.)"><xsl:value-of select="."/></xsl:element></xsl:for-each><xsl:apply-templates/></xsl:element></xsl:template>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...