Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Xpatch Expression 1

Status
Not open for further replies.

Bilberry

Programmer
Dec 17, 2007
111
NL
Hi All,

I need to search within the InvoiceItemDetail node whether a MonetaryAmount exists within the AllowOrCharge, indicatorcoded is always charge and MethodHandlingCoded is always Other, I need to get the value 0.12 back with a XPath expression, how to build that?
Code:
<AllowOrCharge>
  <IndicatorCoded>Charge</IndicatorCoded> 
  <MethodOfHandlingCoded>Other</MethodOfHandlingCoded> 
<TypeOfAllowanceOrCharge>
<MonetaryValue>
<MonetaryAmount>0.12</MonetaryAmount>

I have something like:

InvoiceItemDetail/InvoicePricingDetail/ItemAllowancesOrCharges/ListOfAllowOrCharge/AllowOrCharge[IndicatorCoded='Charge'][MethodOfHandlingCoded='Other']/TypeOfAllowanceOrCharge/MonetaryValue/MonetaryAmount

But this does not get the value, below a part of the XML document:

Code:
- <InvoiceItemDetail>
- <InvoiceBaseItemDetail>
- <LineItemNum>
  <BuyerLineItemNum>1</BuyerLineItemNum> 
  </LineItemNum>
- <ItemIdentifiers>
- <PartNumbers>
- <StandardPartNumber>
- <ProductIdentifierCoded>
  <ProductIdentifierQualifierCoded>EAN8-5-5-1</ProductIdentifierQualifierCoded> 
  <ProductIdentifier>34523454</ProductIdentifier> 
  </ProductIdentifierCoded>
  </StandardPartNumber>
  </PartNumbers>
  </ItemIdentifiers>
- <TotalQuantity>
- <Quantity>
  <QuantityValue>6</QuantityValue> 
- <UnitOfMeasurement>
  <UOMCoded>1</UOMCoded> 
  </UnitOfMeasurement>
  </Quantity>
  </TotalQuantity>
  </InvoiceBaseItemDetail>
- <InvoicePricingDetail>
- <ListOfPrice>
- <Price>
- <UnitPrice>
  <UnitPriceValue>7.23</UnitPriceValue> 
  </UnitPrice>
  </Price>
  </ListOfPrice>
- <Tax>
  <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> 
  <TaxCategoryCoded>StandardRate</TaxCategoryCoded> 
  <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> 
  <TaxPercent>19.000</TaxPercent> 
  <TaxAmount>8.12</TaxAmount> 
  </Tax>
- <ItemAllowancesOrCharges>
- <ListOfAllowOrCharge>
- <AllowOrCharge>
  <IndicatorCoded>Allowance</IndicatorCoded> 
  <MethodOfHandlingCoded>Other</MethodOfHandlingCoded> 
- <AllowanceOrChargeDescription>
- <AllowOrChgDesc>
- <ListOfDescription>
- <Description>
  <DescriptionText>ADR</DescriptionText> 
- <Language>
  <LanguageCoded>en</LanguageCoded> 
  </Language>
  </Description>
  </ListOfDescription>
  <ServiceCoded>Discount</ServiceCoded> 
  </AllowOrChgDesc>
  </AllowanceOrChargeDescription>
- <TypeOfAllowanceOrCharge>
- <MonetaryValue>
  <MonetaryAmount>0.78</MonetaryAmount> 
  </MonetaryValue>
  </TypeOfAllowanceOrCharge>
  </AllowOrCharge>
- <AllowOrCharge>
  <IndicatorCoded>Charge</IndicatorCoded> 
  <MethodOfHandlingCoded>Other</MethodOfHandlingCoded> 
- <TypeOfAllowanceOrCharge>
- <MonetaryValue>
  <MonetaryAmount>0.12</MonetaryAmount> 
  </MonetaryValue>
  </TypeOfAllowanceOrCharge>
  </AllowOrCharge>
  </ListOfAllowOrCharge>
  </ItemAllowancesOrCharges>
- <InvoiceCurrencyTotalValue>
- <MonetaryValue>
  <MonetaryAmount>42.72</MonetaryAmount> 
  </MonetaryValue>
  </InvoiceCurrencyTotalValue>
  </InvoicePricingDetail>
  </InvoiceItemDetail>


TIA,

Bill
 
In this XML document i dont want to have the charges here, i only want to have the values like the first example

Code:
- <InvoiceDetail>
- <ListOfInvoiceItemDetail>
- <InvoiceItemDetail>
- <InvoiceBaseItemDetail>
- <LineItemNum>
  <BuyerLineItemNum>1</BuyerLineItemNum> 
  </LineItemNum>
- <ItemIdentifiers>
- <PartNumbers>
- <StandardPartNumber>
- <ProductIdentifierCoded>
  <ProductIdentifierQualifierCoded>EAN5-5-5-1</ProductIdentifierQualifierCoded> 
  <ProductIdentifier>46467575</ProductIdentifier> 
  </ProductIdentifierCoded>
  </StandardPartNumber>
  </PartNumbers>
  </ItemIdentifiers>
- <TotalQuantity>
- <Quantity>
  <QuantityValue>80</QuantityValue> 
- <UnitOfMeasurement>
  <UOMCoded>1</UOMCoded> 
  </UnitOfMeasurement>
  </Quantity>
  </TotalQuantity>
  </InvoiceBaseItemDetail>
- <InvoicePricingDetail>
- <ListOfPrice>
- <Price>
- <UnitPrice>
  <UnitPriceValue>14.6</UnitPriceValue> 
  </UnitPrice>
  </Price>
  </ListOfPrice>
- <Tax>
  <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> 
  <TaxCategoryCoded>ExemptFromTax</TaxCategoryCoded> 
  <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> 
  <TaxPercent /> 
  <TaxAmount>0</TaxAmount> 
  </Tax>
- <ItemAllowancesOrCharges>
- <ListOfAllowOrCharge>
- <AllowOrCharge>
  <IndicatorCoded>Charge</IndicatorCoded> 
  <MethodOfHandlingCoded>Other</MethodOfHandlingCoded> 
- <AllowanceOrChargeDescription>
- <AllowOrChgDesc>
- <ListOfDescription>
- <Description>
  <DescriptionText>SH</DescriptionText> 
- <Language>
  <LanguageCoded>en</LanguageCoded> 
  </Language>
  </Description>
  </ListOfDescription>
  <ServiceCoded>SpecialHandling</ServiceCoded> 
  </AllowOrChgDesc>
  </AllowanceOrChargeDescription>
- <TypeOfAllowanceOrCharge>
- <MonetaryValue>
  <MonetaryAmount>60</MonetaryAmount> 
  </MonetaryValue>
  </TypeOfAllowanceOrCharge>
  </AllowOrCharge>
- <AllowOrCharge>
  <IndicatorCoded>Charge</IndicatorCoded> 
  <MethodOfHandlingCoded>Other</MethodOfHandlingCoded> 
- <AllowanceOrChargeDescription>
- <AllowOrChgDesc>
- <ListOfDescription>
- <Description>
  <DescriptionText>RAD</DescriptionText> 
- <Language>
  <LanguageCoded>en</LanguageCoded> 
  </Language>
  </Description>
  </ListOfDescription>
  <ServiceCoded>Deposit</ServiceCoded> 
  </AllowOrChgDesc>
  </AllowanceOrChargeDescription>
- <TypeOfAllowanceOrCharge>
- <MonetaryValue>
  <MonetaryAmount>400</MonetaryAmount> 
  </MonetaryValue>
  </TypeOfAllowanceOrCharge>
  </AllowOrCharge>
  </ListOfAllowOrCharge>
  </ItemAllowancesOrCharges>
- <InvoiceCurrencyTotalValue>
- <MonetaryValue>
  <MonetaryAmount>1628</MonetaryAmount> 
  </MonetaryValue>
  </InvoiceCurrencyTotalValue>
  </InvoicePricingDetail>
  </InvoiceItemDetail>

So in the Xpath expression i dont want to have have the values 60, 400 or 1628.

I only want to have the values like the first example only within this node:

Code:
<AllowOrCharge>
  <IndicatorCoded>Charge</IndicatorCoded> 
  <MethodOfHandlingCoded>Other</MethodOfHandlingCoded> 
<TypeOfAllowanceOrCharge>
<MonetaryValue>
<MonetaryAmount>123456</MonetaryAmount>

This node doesnt exist in the second example so i need to get a 0 back.
 
>So in the Xpath expression i dont want to have have the values 60, 400 or 1628.
What is wrong with 60 and 400? They satisfy well the condition on AllowOrCharge.
 
Hi Tsuji,

Thanks a lot for your reply. When the description is filled in (SH, RAD or other descriptions, then i dont need to take the MonetoryAmount

- <AllowOrChgDesc>
- <ListOfDescription>
- <Description>
<DescriptionText>SH</DescriptionText>

I need only to take the MonetaryAmount from the AllowOrcharge[IndicatorCoded = 'Charge' and MethodOfHandlingCoded = 'Other'/TypeOfAllowanceOrCharge/MonetaryValue/MonetaryAmount

When i try this it will also take the 60,400 etc. But i dont want to have these, because these nodes contains a description. I only want to get the MonetoryAmount without description.

Thanks a lot...

 
>When the description is filled in (SH, RAD or other descriptions, then i dont need to take the MonetoryAmount
It is still unclear. Is it that if it be "ADR" you need to take the MonetaryAmount? If that is the case, you just add more conditions, like this.
[tt]
InvoiceItemDetail/InvoicePricingDetail/ItemAllowancesOrCharges/ListOfAllowOrCharge/AllowOrCharge[IndicatorCoded = 'Charge'][MethodOfHandlingCoded = 'Other'][blue][Description/DescriptionText = 'ADR']/[/blue]TypeOfAllowanceOrCharge/MonetaryValue/MonetaryAmount[/tt]
 
Hi Tsuji,

I need to take only the MonetoryAmount within for example the following example:

<AllowOrCharge>
<IndicatorCoded>Charge</IndicatorCoded>
<MethodOfHandlingCoded>Other</MethodOfHandlingCoded>
- <TypeOfAllowanceOrCharge>
- <MonetaryValue>
<MonetaryAmount>0.12</MonetaryAmount>

So with my XPath expression, i need to take the 0.12

If there is something like:

AllowOrCharge>
<IndicatorCoded>Charge</IndicatorCoded>
<MethodOfHandlingCoded>Other</MethodOfHandlingCoded>
- <AllowanceOrChargeDescription>
- <AllowOrChgDesc>
- <ListOfDescription>
- <Description>
<DescriptionText>SH</DescriptionText>
- <Language>
<LanguageCoded>en</LanguageCoded>
</Language>
</Description>
</ListOfDescription>
<ServiceCoded>SpecialHandling</ServiceCoded>
</AllowOrChgDesc>
</AllowanceOrChargeDescription>
- <TypeOfAllowanceOrCharge>
- <MonetaryValue>
<MonetaryAmount>60</MonetaryAmount>
</MonetaryValue>

In this example i dont want to get the 60, because as you can see there is a descriptiontext available( <DescriptionText>SH</DescriptionText>
)

I only want to take the MonetoryAmount without the <DescriptionText> element.

Look at my first XML post, i need to take the values: 0.12 from my second post example: nothing.

I hope that you will understand me correctly. Thanks a lot again...

 
But without the added condition on DescriptionText in my last posting, the xpath of your first post has no problem. You can get 0.12 no problem. If you cannot get it, it is just because you apply it under a wrong context node.

Same for your last post with added condition on DescriptionText.

Nothing is more important for you at the moment is to look at the context node where you apply the two versions of the xpath sofar exhibited.
 
Hi Tsuji,

When i try this:

//InvoiceItemDetail/InvoicePricingDetail/ItemAllowancesOrCharges/ListOfAllowOrCharge/AllowOrCharge[IndicatorCoded = 'Charge' and MethodOfHandlingCoded = 'Other']//MonetaryAmount

I will get the 0.12, thats ok in my first XML example, but when i use the same Xpath expression for my second XML example it will return 60, 400 and 1628 and i dont want these values. How can i exlude the 60 400 and 1628 for my first xpath expression?
 
To exclude 60, 400 and 1628 is easy. The problem still is what is the proper condition! The xpath as of my "25 Apr 08 10:28" would take them all out. Fear is though it is not the condition (on Description/DescriptionText) you really want.
 
Hi Tsuji,

I have tried with the xpath but this does not take the 0.12

//InvoiceItemDetail/InvoicePricingDetail/ItemAllowancesOrCharges/ListOfAllowOrCharge/AllowOrCharge[IndicatorCoded = 'Charge'][MethodOfHandlingCoded = 'Other'][Description/DescriptionText = 'ADR']/TypeOfAllowanceOrCharge/MonetaryValue/MonetaryAmount

What is going wrong?
 
And also within this XML part I do NOT want to take the values: 10560 and 990

Code:
<InvoiceItemDetail>
<InvoiceBaseItemDetail>
<LineItemNum>
<BuyerLineItemNum>1</BuyerLineItemNum>
</LineItemNum>
<ItemIdentifiers>
<PartNumbers>
<StandardPartNumber>
<ProductIdentifierCoded>
<ProductIdentifierQualifierCoded>EAN2-5-5-1</ProductIdentifierQualifierCoded>
<ProductIdentifier>354342143</ProductIdentifier>
</ProductIdentifierCoded>
</StandardPartNumber>
</PartNumbers>
</ItemIdentifiers>
<TotalQuantity>
<Quantity>
<QuantityValue>352</QuantityValue>
<UnitOfMeasurement>
<UOMCoded>1</UOMCoded>
</UnitOfMeasurement>
</Quantity>
</TotalQuantity>
</InvoiceBaseItemDetail>
<InvoicePricingDetail>
<ListOfPrice>
<Price>
<UnitPrice>
<UnitPriceValue>91.1</UnitPriceValue>
</UnitPrice>
</Price>
</ListOfPrice>
<Tax>
<TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded>
<TaxCategoryCoded>ExemptFromTax</TaxCategoryCoded>
<TaxTypeCoded>ValueAddedTax</TaxTypeCoded>
<TaxPercent/>
<TaxAmount>0</TaxAmount>
</Tax>
<ItemAllowancesOrCharges>
<ListOfAllowOrCharge>
<AllowOrCharge>
<IndicatorCoded>Allowance</IndicatorCoded>
<MethodOfHandlingCoded>Other</MethodOfHandlingCoded>
<AllowanceOrChargeDescription>
<AllowOrChgDesc>
<ListOfDescription>
<Description>
<DescriptionText>ADR</DescriptionText>
<Language>
<LanguageCoded>en</LanguageCoded>
</Language>
</Description>
</ListOfDescription>
<ServiceCoded>Discount</ServiceCoded>
</AllowOrChgDesc>
</AllowanceOrChargeDescription>
<TypeOfAllowanceOrCharge>
<MonetaryValue>
<MonetaryAmount>4970.24</MonetaryAmount>
</MonetaryValue>
</TypeOfAllowanceOrCharge>
</AllowOrCharge>
<AllowOrCharge>
<IndicatorCoded>Charge</IndicatorCoded>
<MethodOfHandlingCoded>Other</MethodOfHandlingCoded>
<AllowanceOrChargeDescription>
<AllowOrChgDesc>
<ListOfDescription>
<Description>
<DescriptionText>RAD</DescriptionText>
<Language>
<LanguageCoded>en</LanguageCoded>
</Language>
</Description>
</ListOfDescription>
<ServiceCoded>Deposit</ServiceCoded>
</AllowOrChgDesc>
</AllowanceOrChargeDescription>
<TypeOfAllowanceOrCharge>
<MonetaryValue>
<MonetaryAmount>10560</MonetaryAmount>
</MonetaryValue>
</TypeOfAllowanceOrCharge>
</AllowOrCharge>
</ListOfAllowOrCharge>
</ItemAllowancesOrCharges>
<InvoiceCurrencyTotalValue>
<MonetaryValue>
<MonetaryAmount>37656.96</MonetaryAmount>
</MonetaryValue>
</InvoiceCurrencyTotalValue>
</InvoicePricingDetail>
</InvoiceItemDetail>
<InvoiceItemDetail>
<InvoiceBaseItemDetail>
<LineItemNum>
<BuyerLineItemNum>2</BuyerLineItemNum>
</LineItemNum>
<ItemIdentifiers>
<PartNumbers>
<StandardPartNumber>
<ProductIdentifierCoded>
<ProductIdentifierQualifierCoded>EAN2-5-5-1</ProductIdentifierQualifierCoded>
<ProductIdentifier>23421342132</ProductIdentifier>
</ProductIdentifierCoded>
</StandardPartNumber>
</PartNumbers>
</ItemIdentifiers>
<TotalQuantity>
<Quantity>
<QuantityValue>44</QuantityValue>
<UnitOfMeasurement>
<UOMCoded>1</UOMCoded>
</UnitOfMeasurement>
</Quantity>
</TotalQuantity>
</InvoiceBaseItemDetail>
<InvoicePricingDetail>
<ListOfPrice>
<Price>
<UnitPrice>
<UnitPriceValue>0</UnitPriceValue>
</UnitPrice>
</Price>
</ListOfPrice>
<Tax>
<TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded>
<TaxCategoryCoded>ExemptFromTax</TaxCategoryCoded>
<TaxTypeCoded>ValueAddedTax</TaxTypeCoded>
<TaxPercent/>
<TaxAmount>0</TaxAmount>
</Tax>
<ItemAllowancesOrCharges>
<ListOfAllowOrCharge>
<AllowOrCharge>
<IndicatorCoded>Charge</IndicatorCoded>
<MethodOfHandlingCoded>Other</MethodOfHandlingCoded>
<AllowanceOrChargeDescription>
<AllowOrChgDesc>
<ListOfDescription>
<Description>
<DescriptionText>RAD</DescriptionText>
<Language>
<LanguageCoded>en</LanguageCoded>
</Language>
</Description>
</ListOfDescription>
<ServiceCoded>Deposit</ServiceCoded>
</AllowOrChgDesc>
</AllowanceOrChargeDescription>
<TypeOfAllowanceOrCharge>
<MonetaryValue>
<MonetaryAmount>990</MonetaryAmount>
</MonetaryValue>
</TypeOfAllowanceOrCharge>
</AllowOrCharge>
</ListOfAllowOrCharge>
</ItemAllowancesOrCharges>
<InvoiceCurrencyTotalValue>
<MonetaryValue>
<MonetaryAmount>990</MonetaryAmount>
</MonetaryValue>
</InvoiceCurrencyTotalValue>
</InvoicePricingDetail>
</InvoiceItemDetail>
 
Tsuji do you mean a xpath expression like:


//InvoiceItemDetail/InvoicePricingDetail/ItemAllowancesOrCharges/ListOfAllowOrCharge/AllowOrCharge[//Description/DescriptionText = 'ADR'][IndicatorCoded = 'Charge'][MethodOfHandlingCoded = 'Other']/TypeOfAllowanceOrCharge/MonetaryValue/MonetaryAmount

I the last example it will take the values 10560 and 990, how can we filter out that?

I only want to take charges without a description, like my first example
 
If it is only the absence of the DescriptionText whatever the text of it in case of it presence, then you can simply use the xpath like this.
[tt]
select="InvoiceItemDetail
/InvoicePricingDetail
/ItemAllowancesOrCharges
/ListOfAllowOrCharge/AllowOrCharge
[IndicatorCoded='Charge']
[MethodOfHandlingCoded='Other']
[count(AllowanceOrChargeDescription/AllowOrChgDesc/ListOfDescription/Description/DescriptionText)=0]
/TypeOfAllowanceOrCharge
/MonetaryValue/MonetaryAmount"
[/tt]
 
Hi Tsuji,

I have really tried everything. This give a boolean back (everytime false), but i need to get the values as described earlier. Shortly, it doesnt work. Do you have another idea, or do you know what im doing wrong. You are one of the Guru's of this XML forum part, I hope you can give me the golden solution...
 
Ohh, I think this works, (like yours)

//InvoiceItemDetail/InvoicePricingDetail/ItemAllowancesOrCharges/ListOfAllowOrCharge/AllowOrCharge[count(AllowanceOrChargeDescription/AllowOrChgDesc/ListOfDescription/Description/DescriptionText) = 0 ][IndicatorCoded = 'Charge']
[MethodOfHandlingCoded = 'Other']/TypeOfAllowanceOrCharge/MonetaryValue/MonetaryAmount


Thanks Tsuji...I will try this in my Stylesheet
 
Okay, you're placing // at the front. Again, it just reflects the possible difference of the context node where the xpath is being applied. In any case, glad you finally arrive at an appropriate variation of it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top