Re: [xsl] Some attribute not displayed in output

Subject: Re: [xsl] Some attribute not displayed in output
From: ac <ac@xxxxxxxxxxxxx>
Date: Wed, 26 Aug 2009 23:45:09 -0400

You could possibly simply add a template like

<xsl:template match="o[@t='Info']">
<xsl:element name="{@t}">
<xsl:apply-templates select="a[(@n!='Info') and (@n!='Sender')]"/>
<xsl:apply-templates select="a[(@n='Info') or (@n='Sender')]"/>

which would ensure that attributes are processed first.

But I can not see where the </Header> in your output comes from.


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"?>
  <o t="request">
    <a n="Info">
      <o t="Info">
        <a n="TimeStamp">
          <v s="2009-08-81 12:59:59"/>
       <a n="Sender">
         <o t="Sender">
           <a n="Login">
             <v s="username"/>
      <a n="MissingAttribute">
        <v s="xxx"/>

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

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

<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:if test="(@n='Info') or (@n='Sender') ">
  <xsl:apply-templates select="o"/>

Current Thread