Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to add up attributes present in two xml using xslt
    text
    copied!<p>I have these two xml ,and I want the sum of attibutes in final xml by summing them from given two inputs.Explained below in example </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;chart xmlns="http://www.xyz.in/server/model" labelStep="1" showValues="0"&gt; &lt;categories&gt; &lt;category Label="Bangalore Technical RATH" /&gt; &lt;/categories&gt; &lt;dataset&gt; &lt;set value="3" anchorRadius="2" anchorBorderThickness="3" /&gt; &lt;set value="3" anchorRadius="2" anchorBorderThickness="3" /&gt; &lt;/dataset&gt; &lt;/chart&gt; </code></pre> <p>similar is second input2.xml </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;chart xmlns="http://www.xyz.in/server/model" labelStep="1" showValues="0"&gt; &lt;categories&gt; &lt;category Label="Bangalore Technical RATH" /&gt; &lt;/categories&gt; &lt;dataset&gt; &lt;set value="2" anchorRadius="2" anchorBorderThickness="3" /&gt; &lt;set value="1" anchorRadius="2" anchorBorderThickness="3" /&gt; &lt;/dataset&gt; &lt;/chart&gt; </code></pre> <p>Code I am using for xsl-ttransformation is </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt; &lt;xsl:output method="xml" indent="yes" /&gt; &lt;xsl:variable name="second" select="document('file2.xml')//*[local-name()='set']" /&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[local-name()='set']/@*[local-name()='value']"&gt; &lt;xsl:for-each select="//*[local-name()='set']"&gt; &lt;xsl:variable name="secondvalue" select="$second/@value" /&gt; &lt;xsl:attribute name="value"&gt; &lt;xsl:value-of select="@*[local-name()='value'] + $secondvalue[1]" /&gt; &lt;/xsl:attribute&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>so in final output.xml I need showing only part Interested in </p> <pre><code>&lt;dataset&gt; &lt;set value="5" anchorRadius="2" anchorBorderThickness="3"/&gt; &lt;set value="4" anchorRadius="2" anchorBorderThickness="3"/&gt; &lt;/dataset&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload