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

RE: Suppressing attributes while merging

Subject: RE: Suppressing attributes while merging
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 7 Aug 2002 19:39:48 +0100
xslt copy of
You can take advantage of the fact that if you call <xsl:attribute>
twice for the same element, and the two attributes have the same name,
the second one overwrites the first. The same is true if you create the
attributes using <xsl:copy> or <xsl:copy-of>

So just do:

<xslt:copy-of select="$first2/@*" />
<xslt:copy-of select="$first1/@*" />

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Kalyan Kumar Mudumbai
> Sent: 07 August 2002 15:23
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Suppressing attributes while merging
> 
> 
> Hi All,
>      I've a query on how to suppress the merging of attributes in 
> one condition. If I have an xml file with a node
> 
> <Book Name="BestBook" ISBN="1234" Edition="2nd ed."/>
> 
> and another xml file with a node
> 
> <Book Edition="3nd ed." Cost="15$"/>
> 
> I need to merge these two xml files and while merging the 
> resultant node has to be in the following form:
> 
> <Book Name="BestBook" ISBN="1234" Edition="2nd ed." Cost="15$"/>
> 
> In the above example, the 'Edition' attribute in the second file 
> has to being suppressed, as it is shown in the output.
> 
> Now I'm having the node in 1st xml file in $first1 and the node in 
> 2nd xml file in $first2 and I've been trying the following 
> approach, which doesn't work.
> 
> <xslt:copy-of select="$first1/@*" />
> <xslt:for-each select="$first2/@*">
>    <xslt:variable name="attr_1" select="name(.)"/>
>    <xslt:variable name="val_1" select="."/>
>    <xslt:for-each select="$first1/@*">
>      <xslt:variable name="attr_2" select="name(.)"/>
>      <xslt:if test="not($attr_1=$attr_2)">
>        <xslt:copy-of select="$val_1"/>
>      </xslt:if>
>    </xslt:for-each>
> </xslt:for-each>
> 
> In the above approach, I copy all the attributes of the node in 
> file1 initially and then while copying the attributes of the node 
> in file2, I check for the presence of an attribute with the same 
> name in the node of file1 and in it's absence I copy the 
> attribute, of else, I do not. But there is some problem, with the 
> logic or with the way it's written, so it doesn't work in the 
> expected way. Can some one please help me in figuring out the 
> right way.
>      Thanks,
> 
> Regards,
> Kalyan.
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.