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

RE: Re: Re: Re: Converting specific child elements int

Subject: RE: Re: Re: Re: Converting specific child elements into att riutes of parent
From: "Sindigi, Ganesh K" <SindiGK@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 3 Nov 2003 10:49:05 -0700
cannot add attribute
This did not give the error and resulted in expected results.  I could get
the result with JRE itself i.e., without having to specify 
the -Xbootclasspath/p flag.  Does that mean XalanJ 2.4.1, Saxon 6.5.3,
MSXML3, etc are suppressing this error? Whether the processors which issue
this error are XSLT compliant or is it the otherway? 

Thanks to all for spending your time on this and helping to resolve this.

-Ganesh.

-----Original Message-----
From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Sent: Monday, November 03, 2003 7:19 AM
To: Sindigi, Ganesh K
Cc: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: Re:  Re: Re: Re: Converting specific child elements into
att riutes of parent


Hi Ganesh,

> Still i am not able to come out of this loop.  This is really frustrating.
> Now I tried with XalanJ 2.5.0 and XalanJ 2.5.2 with the classpath set to
> these version's jar file using -Xbootclasspath/p(exactly how its described
> in Xalan-J FAQ at:  http://xml.apache.org/xalan-j/faq.html#faq-N100CB &
> http://xml.apache.org/xalan-j/faq.html#faq-N100B4).  Now the earlier error
> gone
>
> file:///C:/working/XML/elmToAtt.xsl; Line #31; Column #5; Cannot add
> attribute id after child nodes or before an element is produced.
Attribute
> will be ignored.
> file:///C:/working/XML/elmToAtt.xsl; Line #31; Column #5; Cannot add
> attribute id after child nodes or before an element is produced.
Attribute
> will be ignored. 
>
> However its producing the required output when I run this within the
> application. Now i need to eliminate this error. Anybody got clue on
> this ?

These are reports of errors in your stylesheet. You are currently
creating an attribute and adding it to an element after you've already
added children to that element, and that's not allowed in XSLT. The
cause is the <xsl:apply-templates> instruction that applies templates
to all the children of the element, when some of the children might
cause the generation of attributes and others the copying of elements.

Try the following stylesheet, which should fix the problem:

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:my="my:my"
   exclude-result-prefixes="my"
   >

   <xsl:output omit-xml-declaration="yes" indent="yes"/>
   <xsl:strip-space elements="*"/>

   <my:elNames>
      <name>id</name>
   </my:elNames>

   <xsl:variable name="elNames"
      select="document('')/*/my:elNames/name"/>

   <xsl:template match="@* | node()">
      <xsl:copy>
         <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
   </xsl:template>

   <xsl:template match="*">
      <xsl:choose>
         <xsl:when test="not(name() = $elNames)">
            <xsl:copy>
               <xsl:copy-of select="@*"/>
               <xsl:apply-templates select="*[name() = $elNames]"/>
               <xsl:apply-templates
                 select="node()[not(name() = $elNames)]"/>
            </xsl:copy>
         </xsl:when>
         <xsl:otherwise>
            <xsl:attribute name="{name()}">
               <xsl:value-of select="."/>
            </xsl:attribute>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

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

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.