marina Posted June 25, 2006 Share Posted June 25, 2006 How can I convert attributes to child elements?<marca href="http://www.hp.pt">HP</marca>to<marca>HP <href>http://www.hp.pt</href></marca> Link to comment Share on other sites More sharing options...
boen_robot Posted June 25, 2006 Share Posted June 25, 2006 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 More sharing options...
marina Posted June 25, 2006 Author Share Posted June 25, 2006 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 More sharing options...
boen_robot Posted June 25, 2006 Share Posted June 25, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now