Guest John Stubbe Posted August 7, 2006 Share Posted August 7, 2006 Dear XSLT experts I have an issue regarding adding an extra attribute under a transformation. I have an entry in my source XML file that consists of content from a WYSIWYG editor. I need to duplicate an attribute to all image tags which has been inserted. My source XML file looks something like below:<root><content> This is some text <b>bold</b> <img src="picture.jpg" img-id="picture.jpg" /> <br /> Some more text and images <img src="picture2.jpg" img-id="picture2.jpg" /> </content> </root>When I do an XSL transformation I need to create a HTML page with the content from the “content” node but to each img tag the result should look something like this (an ekstra attribute “usemap” is added which is a copy of the img-id:<img src="picture.jpg" img-id="picture.jpg" usemap=”picture.jpg” />How is this possible ?Thanks in advance CheersJohn StubbeDenmark Link to comment Share on other sites More sharing options...
boen_robot Posted August 7, 2006 Share Posted August 7, 2006 Looks simple enough. If it doesn't get more complicated then this, you should be alright with something like this: <xsl:template match="/root"><xsl:apply-temlpates/></xsl:template><xsl:temlpate match="content"><!--Change this to the wrapper you need. Like a <div> maybe?--><content><xsl:apply-temlpates/></xsl:temlpate><xsl:template match="img"><img src="{@src}" img-id="{@src}" /></xsl:template> Please note that this approach might requre you to add every other available element as their own temlpate or unify them somehow. I have a hunch on how this unification may be done, but scince I don't have the complete answer right now, I can grant you this: <xsl:template match="br"><br /></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