xsl-list
[Top] [All Lists]

Re: XML reformatting <xsl:element & <xsl:for-each

2003-01-07 07:41:19
Hi Alan,

I'm trying to use the <xsl:element> in the template for the <Table>
section and loop through all the child nodes of <Table> to put them
in the output xml, but It keeps saying that the element name is not
a QName, How can I accomplish this???

You're trying to create the element name dynamically, from a function,
so the name attribute of <xsl:element> should be an attribute value
template: put {}s around the function call. Rather than:

                <xsl:element name="name()">
                        <xsl:value-of select="current()/text()"/>
                </xsl:element>

use:

  <xsl:element name="{name()}">
    <xsl:value-of select="." />
  </xsl:element>

or, better, since you're just copying an existing element, use
xsl:copy:

  <xsl:copy>
    <xsl:value-of select="." />
  </xsl:copy>

or, since none of your elements have child elements, this is
equivalent to:

  <xsl:copy-of select="." />

I'm also getting Odd errors about <xsl:text>, 'Unexpected  Child'.

In XSLT 1.0, <xsl:text> can't have children. Rather than:

        <xsl:text>
                <xsl:value-of select="current()/text()"/>
        </xsl:text>

you should use just:

  <xsl:value-of select="current()/text()" />

or even just:

  <xsl:value-of select="." />

I think that the easiest way to create your output is to just copy all
the element children of the <Table> element directly using
<xsl:copy-of>. For example, you could do your transformation with:

<xsl:template match="NewDataSet">
  <data>
    <xsl:copy-of select="Table/*" />
    <fabrics>
      <xsl:copy-of select="Table1/FabricId" />
    </fabrics>
    <attributes>
      <xsl:for-each select="Table2">
        <attribute id="{Attributeid}">
          <xsl:value-of select="Setting" />
        </attribute>
      </xsl:for-each>
    </attributes>
  </data>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list