Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL - Get Distinct based on document xml and input xml mapping
    primarykey
    data
    text
    <p>I am referring an xml file(document.xml), through document function. Based on the input xml id value, I am taking the corresponding value from document.xml. The output will have this corresponding value and the position in input, as shown in the actualoutput.xml. However, would like to generate an output xml like expectedOutput.xml, having the attributes Value. Could anyone please point how to change my xsl file to get the expectedOutput.xml?</p> <p>below are the files XslFile.xsl</p> <pre><code>&lt;xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;result&gt; &lt;xsl:apply-templates select="/*/id"/&gt; &lt;/result&gt; &lt;/xsl:template&gt; &lt;xsl:template match="id"&gt; &lt;xsl:variable name="currencydetails" select="document('document.xml')/doc"/&gt; &lt;xsl:variable name="id"&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:variable&gt; &lt;mapValue&gt; &lt;xsl:variable name="fromDocument" select="$currencydetails/id[@value=$id]"/&gt; &lt;xsl:value-of select="$fromDocument"/&gt; &lt;/mapValue&gt; &lt;position&gt; &lt;xsl:value-of select="position()"/&gt; &lt;/position&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>document.xml</p> <pre><code> &lt;doc&gt; &lt;id value="123"&gt;abc&lt;/id&gt; &lt;id value="456"&gt;abc&lt;/id&gt; &lt;id value="011"&gt;def&lt;/id&gt; &lt;id value="rty"&gt;ghj&lt;/id&gt; &lt;id value="iop"&gt;qwd&lt;/id&gt; &lt;id value="321"&gt;ply&lt;/id&gt; &lt;/doc&gt; </code></pre> <p>input.xml</p> <pre><code> &lt;Root&gt; &lt;id&gt;123&lt;/id&gt; &lt;id&gt;321&lt;/id&gt; &lt;id&gt;897&lt;/id&gt; &lt;id&gt;011&lt;/id&gt; &lt;id&gt;456&lt;/id&gt; &lt;/Root&gt; </code></pre> <p>actualoutput.xml - I am able to reach only till here</p> <pre><code> &lt;result&gt; &lt;mapValue&gt;abc&lt;/mapValue&gt; &lt;position&gt;1&lt;/position&gt; &lt;mapValue&gt;ply&lt;/mapValue&gt; &lt;position&gt;2&lt;/position&gt; &lt;mapValue/&gt; &lt;position&gt;3&lt;/position&gt; &lt;mapValue&gt;def&lt;/mapValue&gt; &lt;position&gt;4&lt;/position&gt; &lt;mapValue&gt;abc&lt;/mapValue&gt; &lt;position&gt;5&lt;/position&gt; &lt;/result&gt; </code></pre> <p>expectedoutput.xml - what i want</p> <pre><code> &lt;result&gt; &lt;map Value="abc"&gt; &lt;position&gt;1&lt;/position&gt; &lt;position&gt;5&lt;/position&gt; &lt;/map&gt; &lt;map Value="nomatch"&gt; &lt;position&gt;3&lt;/position&gt; &lt;/map&gt; &lt;map Value="def"&gt; &lt;position&gt;4&lt;/position&gt; &lt;/map&gt; &lt;map Value="ply"&gt; &lt;position&gt;2&lt;/position&gt; &lt;/map&gt; &lt;/result&gt; </code></pre> <hr> <p>Thanks. I will read more about xsl:number and position() function</p> <p>However, for the above solution, I get the below response. Could you please guide/help me. The output should be mapped on the basis of value of 'fromdocument'.</p> <pre><code>&lt;result&gt; &lt;map value="abc"/&gt; &lt;position&gt;1&lt;/position&gt; &lt;map value="ply"/&gt; &lt;position&gt;6&lt;/position&gt; &lt;map value=""/&gt; &lt;position/&gt; &lt;map value="def"/&gt; &lt;position&gt;3&lt;/position&gt; &lt;map value="abc"/&gt; &lt;position&gt;2&lt;/position&gt; &lt;/result&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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