Subject: RE: [xsl] Suppressing attributes while merging From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Wed, 7 Aug 2002 19:39:48 +0100 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Suppressing attributes while , Kalyan Kumar Mudumba | Thread | [xsl] The operator '!=' returns fal, Jerome Louvel |
RE: [xsl] xml-stylesheet and vars, Michael Kay | Date | RE: [xsl] The operator '!=' returns, Michael Kay |
Month |