Below is my source schema
<ns0:xyz xmlns:ns0="http://abc/xyz">
<main>
<zzz/></zzz>
<yyy/></yyy>
</main>
<Lines>
<Line>
<LineNum></LineNum>
<Linerate></Linerate>
</Line>
</Lines>
and Below is my input file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xyz xmlns="http://abc/xyz">
<main>
<zzz>12</zzz>
<yyy>11</yyy>
</main>
<Lines>
<Line>
<LineNum>1</LineNum>
<Linerate>0.5</Linerate>
</Line>
<LineNum>3</LineNum>
<Linerate>0.2</Linerate>
</Line>
<Line>
<LineNum>5</LineNum>
<Linerate>0.5</Linerate>
</Line>
</Lines>
I need to compare the line records and check if the Linerate element has similar value , then irrespective of the number of records in the source file , my destination file should have only 1 record with that particular Line rate value.
And for every distinct Linerate value , there should be respective record for it.
The Linerate value should be assigned to percent node in the destination
The Cumulative sum value of the LineNum value should be assigned to Amount in destination(if Linerate value is same across the records in the source)
Linerate * cumulative sum of LineNum should be assinged to AdditionalAmount in destination
Below is the expected output file
<LineSummary>
<Percent>0.5</Percent>
<Amount>6</Amount>
<AdditionalAmount>3</AdditionalAmount>
</LineSummary>
<LineSummary>
<Percent>0.2</Percent>
<Amount>3</Amount>
<AdditionalAmount>0.6</AdditionalAmount>
</LineSummary>
Below is the XSLT code used in my BizTalk Map.
<xsl:variable name="unique-LineRate" select="//Lines/Line[not(Linerate=preceding-sibling::Line/Linerate)]/Linerate" />
<xsl:for-each select="$unique-LineRate">
<LineSummary>
<xsl:variable name="LineSum" select="sum(//Lines/Line[Linerate=current()]/LineNum)" />
<Percent><xsl:value-of select="current()"/></Percent>
<Amount><xsl:value-of select="$LineSum" /></Amount>
<AdditionalAmount><xsl:value-of select="current() * $LineSum"/></AdditionalAmount>
</LineSummary>
</xsl:for-each>
If my source schema "ElementFormDefault" value is kept as unqualified or default, the I get an error as : Input validation error: The element 'xyz' in namespace 'http://abc/xyz' has invalid child element 'main' in namespace 'http://abc/xyz'. List of possible elements expected: 'main'.
If my source schema "ElementFormDefault" is kept as Qualified,then the XSLT doesn't work. I am sure it has to do something with the namespace issue or element tagging But i am not sure exactly where i need to make the change.
Do I need to prefix with the XPath or the namespace to all the elements in the XSLT?