Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.