timbrown Posted June 7, 2007 Share Posted June 7, 2007 Hi, ??? I am trying to use phps tranformToXML function. I can get it to work ok but I am having problems adding attributes. example: something.xml <app> <id>app1</id> <title>a title</title> <content>some content</content> </app> something.xsl <xsl:template match="id"> <xsl:attribute name="id"> <xsl:value-of select="."> </xsl:attribute> </xsl:template> <xsl:template match="app"> <div> <xsl:apply-templates/> </div> </xsl:template> the idea of this is to create an attribute within "app" called "id" and give it the value of the "id" element within the xml file. this works fine when just linking the stylesheet to the xml file and displaying it in a browser, but when I try to put the files through transformToXML I get an error like - "Cannot add attributes to an element if children have already been added to the element" I have tried moving things around to no avail. Any ideas? Tim. Link to comment https://forums.phpfreaks.com/topic/54573-solved-xml-newbie/ Share on other sites More sharing options...
timbrown Posted June 7, 2007 Author Share Posted June 7, 2007 Sorry! Fixed it myself by putting the attribute line inside the app template. Link to comment https://forums.phpfreaks.com/topic/54573-solved-xml-newbie/#findComment-269883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.