[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Suppressing attributes while merging


Subject: [xsl] Suppressing attributes while merging
From: "Kalyan Kumar Mudumbai" <kalyan_tech@xxxxxxxxxxxxxx>
Date: 7 Aug 2002 14:23:17 -0000

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




Current Thread
Keywords