I am trying to write something for another individual and im stuck on the final part of the stylesheet.
We have two XML Documents:
TestXML.xml:
<rootNode>
<header>
<title agg="sum">1</title>
<records agg="sum">10</records>
<number agg="min">5</number>
</header>
</rootNode>
and TestXMLTwo.xml:
<rootNode>
<header>
<title agg="sum">2</title>
<records agg="sum">20</records>
<number agg="min">15</number>
</header>
</rootNode>
Where if the node has its agg attribute equal to ‘sum’ we combine the values of the two documents nodes. I am doing this using:
<xsl:param name="InputFileOne">[EditedOut]\TestXML.xml</xsl:param>
<xsl:param name="InputFileTwo">[EditedOut]\TestXMLTwo.xml</xsl:param>
<xsl:template match="node()|@*">
<xsl:call-template name="ConcatFiles"/>
</xsl:template>
<xsl:template name="ConcatFiles">
<xsl:variable name="tempStoreDocOne" select ="document($InputFileOne)/rootNode/header" />
<xsl:variable name="tempStoreDocTwo" select ="document($InputFileTwo)/rootNode/header" />
<xsl:element name="rootNode">
<xsl:element name="header">
<xsl:for-each select="$tempStoreDocOne/node()">
<xsl:choose>
<xsl:when test="./@agg = 'sum'">
<xsl:variable name="tempElementDocTwo" select ="$tempStoreDocTwo/."/>
<xsl:element name="{name(.)}">
<xsl:value-of select=". + $tempElementDocTwo"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{name(.)}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
However on the line <xsl:value-of select=". + $tempElementDocTwo"/> I just get a value of ‘22016’ for the <title> and 22025 for the <records>. Can someone enlighten me as to where I’m going wrong?
Change
<xsl:for-each select="$tempStoreDocOne/node()">to<xsl:for-each select="$tempStoreDocOne/*">, then add a variable storing the position i.e.inside of the
for-each, then changeto
Currently you are accessing the string value of the complete
headerelement in the second document which is the concatenation of its descendant nodes while you want to access the child element with the same position as the one in the first document.