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

Re: Re: Converting specific child elements into att ri

Subject: Re: Re: Converting specific child elements into att riutes of parent
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 1 Nov 2003 12:04:52 +0100
xsl ri
> I would guess that the stylesheet was run on a document where <id>
> wasn't a first child, that would generate the error quoted.
>

Not really. I rearranged the source xml document like this:

<customerList>
  <customer>
    <field>
      <value>cust1</value>
      <id>customerId</id>
    </field>
    <field>
      <value>Customer  1</value>
      <id>customerName</id>
    </field>
    <fieldGroup>
      <fieldList>
        <field>
          <value>98th  Street </value>
          <id>street</id>
        </field>
        <field>
          <value>Chicago</value>
          <id>city</id>
        </field>
      </fieldList>
      <id>homeAddress</id>
    </fieldGroup>
    <fieldGroup>
      <fieldList>
        <field>
          <value>128th  Street</value>
          <id>street</id>
        </field>
        <field>
          <value>Chicago</value>
          <id>city</id>
        </field>
      </fieldList>
      <id>companyAddress</id>
    </fieldGroup>
  </customer>
</customerList>


and using the same stylesheet:

<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/>
        </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>

 I get the correct output:

<customerList>
   <customer>
      <field id="customerId">cust1</field>
      <field id="customerName">Customer  1</field>
      <fieldGroup id="homeAddress">
         <fieldList>
            <field id="street">98th  Street </field>
            <field id="city">Chicago</field>
         </fieldList>
      </fieldGroup>
      <fieldGroup id="companyAddress">
         <fieldList>
            <field id="street">128th  Street</field>
            <field id="city">Chicago</field>
         </fieldList>
      </fieldGroup>
   </customer>
</customerList>

I used Saxon 6.5.3, Msxml3/4, and  .Net xsltTransform without any problem.

Xalan J 2.4.1 and Xalan C 1.5 also produce this output, but issue several of
the following messages:

"Cannot add attribute id after child nodes or before an element is produced.
Attribute will be ignored."


To prove that the reason is elesewhere I modified the code as recommended by
you:

replaced:

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

with:

    <xsl:copy>
      <xsl:apply-templates select="*[name()=$elNames]"/>
      <xsl:apply-templates select="@* | node()[not(name()=$elNames)]"/>
    </xsl:copy>

There was no effect. XalanJ 2.4.1 still produces the correct result issuing
the same several error messages as before the code modification.

Therefore the question about the strange error messages issued by XalanJ
remains open.


Could somebody, please, explain them?



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL









 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.