You are not logged in.

#1 2007-05-28 18:39:09

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

XSLT Element tags don't appear

Hi guys,

I'm processing an XML file that some PHP I wrote produces, in the simple format

<root>
  <dir>
    <file>file1</file>
    <file>file2</file>
  </dir>
  <dir>
    <file>file3</file>
  </dir>
</root>

The XSL stylesheet I'm using atm outputs CDATA elements to replace all 'dir's with 'ul's and all 'file's with 'li's, generating a neat list menu of a server directory.

The problem is simply that I want to replace my CDATA elements with xsl:element elements, but they don't work! So eg. I've tried replacing

<![CDATA[<ul>]]>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
<![CDATA[</ul>]]>

with this:

<xsl:element name="ul" namespace="http://w3.org/1999/XHTML">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>

Using this within my XSL stylesheet, the UL element doesn't appear anywhere...

Even this test:

<xsl:template match="*">
  <xsl:element name="test">
    <xsl:value-of select="."/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

doesn't work! No wrapper element is produced for the displayed values.

I really can't see what's wrong here.. it's bizarre. Even more bizarrely, when viewing the resulting XML from various tutorials relating to this, none of them have contained the tag described by the xsl:element in the tutorial's XSL stylesheet. I've viewed the results in several browsers on several systems, so it's no browser problem.. am I misunderstanding the use of xsl:element?

- Dave

Last edited by KomodoDave (2007-05-28 18:39:55)

Offline

#2 2007-05-29 23:09:35

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: XSLT Element tags don't appear

Man, I was really hoping someone would help me figure this out.. I don't know what it is.

I wondered if the fact I'm transforming server-side via PHP might be causing the problem. It's not though - I linked the XSL stylesheet from within the XML file itself and loaded to view - exactly the same problem; no element instructions in the XSL have produced an element within the outputted code.

The templates are being processed for sure; test outputs within my defined xsl:element elements have printed the text, as expected.

- Dave

Offline

#3 2007-05-30 00:04:22

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: XSLT Element tags don't appear

I just copied this example's XML and XSL file directly, then had a look at the result in my browser. Their own result file doesn't seem to show what you'd expect... there are no 'singer' elements in there, and equally my own output displays none of the xsl:element output.

- Dave

Offline

Board footer

Powered by FluxBB