Hi All

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?

Hi All

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?

Hi All,

There is some problem with attachment. below are the files
XslFile.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <result>
            <xsl:apply-templates select="/*/id"/>

        </result>
    </xsl:template>

    <xsl:template match="id">
        <xsl:variable name="currencydetails" select="document('document.xml')/doc" />
        <xsl:variable name="id">
            <xsl:value-of select="."/>
        </xsl:variable>
        <mapValue>
            <xsl:variable name="fromDocument" select="$currencydetails/id[@value=$id]" />
            <xsl:value-of select="$fromDocument"></xsl:value-of>
        </mapValue>
        <position>
            <xsl:value-of select="position()"/>
        </position>


    </xsl:template>
</xsl:stylesheet>

document.xml

<doc>
    <id value ="123">abc</id>
    <id value ="456">abc</id>
    <id value ="011">def</id>
    <id value ="rty">ghj</id>
    <id value ="iop">qwd</id>
    <id value ="321">ply</id>
</doc>

input.xml

<Root>
    <id>123</id>
    <id>321</id>
    <id>897</id>
    <id>011</id>
    <id>456</id>
</Root>

actualoutput.xml

<?xml version="1.0" encoding="UTF-8"?>
<result>
    <mapValue>abc</mapValue>
    <position>1</position>
    <mapValue>ply</mapValue>
    <position>2</position>
    <mapValue/>
    <position>3</position>
    <mapValue>def</mapValue>
    <position>4</position>
    <mapValue>abc</mapValue>
    <position>5</position>
</result>

expectedOutput.xml

<?xml version="1.0" encoding="UTF-8"?>
<result>
    <map Value ="abc">
    <position>1</position>
    <position>5</position>
    </map>
    <map Value ="nomatch">
    <position>3</position>
    </map>
    <map Value="def">
    <position>4</position>
    </map>
    <map Value ="ply">
    <position>2</position>
    </map>
</result>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.