[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: XML reformatting <xsl:element & <xsl:for-each
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 7 Jan 2003 14:41:19 +0000
reformatting xml using xsl
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.