Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:06:22+00:00 2026-05-26T10:06:22+00:00

I am referring an xml file(document.xml), through document function. Based on the input xml

  • 0

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?

below are the files
XslFile.xsl

<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">
    <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"/>
        </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 – I am able to reach only till here

    <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 – what i want

    <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>

Thanks. I will read more about xsl:number and position() function

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’.

<result>
    <map value="abc"/>
    <position>1</position>
    <map value="ply"/>
    <position>6</position>
    <map value=""/>
    <position/>
    <map value="def"/>
    <position>3</position>
    <map value="abc"/>
    <position>2</position>
</result>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:06:22+00:00Added an answer on May 26, 2026 at 10:06 am

    Change

    <mapValue>
        <xsl:variable name="fromDocument" select="$currencydetails/id[@value=$id]"/>
        <xsl:value-of select="$fromDocument"/>
    </mapValue>
    

    to

    <xsl:variable name="fromDocument" select="$currencydetails/id[@value=$id]"/>
    <map value="{$fromDocument}"/>
    

    Change

    <position>
        <xsl:value-of select="position()"/>
    </position>
    

    to

    <position>
        <xsl:number select="$fromDocument"/>
    </position>
    

    or in XSLT 1.0,

    <position>
        <xsl:for-each select="$fromDocument">
            <xsl:number/>
        </xsl:for-each>
    </position>
    

    (You’re one of many people who has guessed wrongly what position() does without reading the spec).

    And (a stylistic and performance improvement) change

    <xsl:variable name="id">
        <xsl:value-of select="."/>
    </xsl:variable>
    

    to

    <xsl:variable name="id" select="."/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML file like this: <Document> <Tests> <Test> <Name>A</Name> <Value>0.01</Value> <Result>Pass</Result> </Test>
Referring here A is a precompiled Java class (I also have the source file)
I have defined schema for xml in file packetTemplate.xsd.Using ms tool xsd.exe i have
I have an XML file that looks like this <library> <book> <title>Title</title> <author>author</author> <price>20</price>
XML documents can be localized by referring to an external DTD document that contains
I am making a CSS file for an XML document. I need to insert
I needed to use XSL to generate simple plain text output from XML. Since
Referring to the first answer about python's bound and unbound methods here, I have
Hi I want to copy an xml file and insert in a specific element
I am referring to the XML 1.1 spec . Look at the definition of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.