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 7944725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:38:18+00:00 2026-06-04T00:38:18+00:00

Halo, I have this xml document: <document> <Line> <Line-Item> <ID>5</ID> <Quantity>100</Quantity> </Line-Item> </Line> <Line>

  • 0

Halo,

I have this xml document:

<document>
<Line>
    <Line-Item>
        <ID>5</ID>
        <Quantity>100</Quantity>                
    </Line-Item>
</Line>
<Line>
    <Line-Item>
        <ID>6</ID>
        <Quantity>9</Quantity>              
    </Line-Item>
</Line>
<Line>
    <Line-Item>
        <ID>60</ID>
        <Quantity>3020</Quantity>               
    </Line-Item>
</Line>
</document>

And lookup file with table:

<lookup>
    <Code>
        <LookupID>5</LookupID>
        <LookupQuantity>25</LookupQuantity>
    </Code>
    <Code>
        <LookupID>6</LookupID>
        <LookupQuantity>3</LookupQuantity>
    </Code>
    <Code>
        <LookupID>70</LookupID>
        <LookupQuantity>3</LookupQuantity>
    </Code>
</lookup>

I should check lookup tables field lookup/Code/LookupId with document Line/Line-Item/ID. if lookup/Code/LookupId=document/Line/Line-Item/ID then document/Line/Line-Item/Quantity=document/Line/Line-Item/Quantity div lookup/Code/LookupQuantity, otherwise document/Line/Line-Item/Quantity=document/Line/Line-Item/Quantity

Needed result:

<document>
<Line>
    <Line-Item>
        <ID>5</ID>
        <Quantity>4</Quantity>              
    </Line-Item>
</Line>
<Line>
    <Line-Item>
        <ID>6</ID>
        <Quantity>3</Quantity>              
    </Line-Item>
</Line>
<Line>
    <Line-Item>
        <ID>60</ID>
        <Quantity>3020</Quantity>               
    </Line-Item>
</Line>
</document>

My xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:key name="skRez" match="LookupQuantity" use="../LookupID"/>
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="Line/Line-Item/Quantity">
        <xsl:variable name="inputS" select="..//ID"/>
        <xsl:variable name="inputQ" select="..//Quantity"/>
            <OrderedQuantity>
                <xsl:for-each select="document('lookup.xml')">
                    <xsl:for-each select="key('skRez',$inputS)">
                        <xsl:variable name="Quantity" select="."/>
                        <xsl:choose>
                            <xsl:when test="$Quantity"><xsl:value-of select="ceiling($inputQ div $Quantity)"/></xsl:when>
                            <xsl:otherwise><xsl:value-of select="$inputQ"/></xsl:otherwise>
                        </xsl:choose>                       
                    </xsl:for-each>
                </xsl:for-each>
            </OrderedQuantity>
    </xsl:template>
</xsl:stylesheet>
  • 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-06-04T00:38:20+00:00Added an answer on June 4, 2026 at 12:38 am

    To do this, you can define a variable to hold the look-up data

    <xsl:variable name="lookup" select="document('Lookup.xml')/lookup"/>
    

    And then you can look-up the quantity for a particular Line-Item like so (In this case, the XSLT is currently positioned on a Quantity element within a Line-Item)

    <xsl:variable name="quantity" 
      select="$lookup//Code[LookupID = current()/../ID]/LookupQuantity"/>
    

    If nothing was returned by this variable, then you know the element was not in the look-up

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:variable name="lookup" select="document('Lookup.xml')/lookup"/>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    
       <xsl:template match="Line-Item/Quantity">
          <xsl:variable name="quantity" 
             select="$lookup//Code[LookupID = current()/../ID]/LookupQuantity"/>
          <Quantity>
             <xsl:choose>
                <xsl:when test="number($quantity) = number($quantity)">
                   <xsl:value-of select="number(.) div number($quantity)"/>
                </xsl:when>
                <xsl:otherwise>
                   <xsl:value-of select="."/>
                </xsl:otherwise>
             </xsl:choose>
          </Quantity>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <document>
       <Line>
          <Line-Item>
             <ID>5</ID>
             <Quantity>4</Quantity>
          </Line-Item>
       </Line>
       <Line>
          <Line-Item>
             <ID>6</ID>
             <Quantity>3</Quantity>
          </Line-Item>
       </Line>
       <Line>
          <Line-Item>
             <ID>60</ID>
             <Quantity>3020</Quantity>
          </Line-Item>
       </Line>
    </document>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please take a look at this: http://halo.meredevelopment.co.uk/2011/11/creative-and-digital-media-apprenticeship/ The menu item 'Halo Home' has the
I have a script that creates a table like this: class TableClass < Table
I'm trying to write my own code for a 'friends-of-friends' algorithm. This algorithm acts
Well, I'm working with Bungie's Halo Reach API. Right now my code will get
What can I do to remove this warning in Flex? I'm using the Halo
Halo I'm sure this question has been asked many times in the past, but
Does any one have any experience on how to implement the halo(outline) effect for
This is the only official documentation available for the Halo: Reach stats API. If
I am porting one of my old javascript file to compatible with requireJS. This
As far as I know, the support for library://ns.adobe.com/flex/halo namespace has been dropped, and

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.