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

Re: Some attribute not displayed in output

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

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')]"/>
</xsl:element>
</xsl:template>


which would ensure that attributes are processed first.

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

Cheers,
ac



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

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-2011 All Rights Reserved.