[xsl] Some attribute not displayed in output

Subject: [xsl] Some attribute not displayed in output
From: lee qm <akimilee@xxxxxxxxx>
Date: Thu, 27 Aug 2009 09:56:41 +0800
I had following src xml file which needs to convert to the output.xml
given below.
I found some of the attributes ("MissingAttribute" in example given
below) is not written to the output.xml with the stylesheet given.
I check the spec and found that adding attribute after child node is
added is illegal.

Can someone help me on how to modify the stylesheet to get the
expected output (where "MissingAttribute" appeared as a attribute of
Header element)?

src.xml (simplied version, the actual src files had many 'a' element)
-----------
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <o t="request">
    <a n="Info">
      <o t="Info">
        <a n="TimeStamp">
          <v s="2009-08-81 12:59:59"/>
        </a>
       <a n="Sender">
         <o t="Sender">
           <a n="Login">
             <v s="username"/>
          </a>
        </o>
      </a>
      <a n="MissingAttribute">
        <v s="xxx"/>
      </a>
    </o>
  </a>
  </o>
</data>

output.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<request>
<Info TimeStamp="2009-08-81 12:59:59" MissingAttribute="xxx">
<Sender Login="username"/>
</Header>
</request>

Stylesheet
----------------
<xsl:template match="o">
 <xsl:element name="{@t}">
  <xsl:apply-templates select="a"/>
 </xsl:element>
</xsl:template>

<xsl:template match="a">
 <xsl:if test="(@n!='Info') and (@n!='Sender') ">
  <xsl:attribute name="{@n}">
   <xsl:for-each select="v">
    <xsl:value-of select="@s"/>
   </xsl:for-each>
   </xsl:attribute>
 </xsl:if>
 <xsl:if test="(@n='Info') or (@n='Sender') ">
  <xsl:apply-templates select="o"/>
 </xsl:if>
</xsl:template>

Current Thread