AntSCript to extract xml tag having specific matching string in attribute value from xml file - ant

I have and XML file as below
<sca:composite xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:atleastonce="http://www.tibco.com/wrm/policy/atleastonce" xmlns:common="http://xsd.tns.tibco.com/n2/models/common" xmlns:compositeext="http://schemas.tibco.com/amx/3.0/compositeext" xmlns:jdbc="http://xsd.tns.tibco.com/amf/models/sharedresource/jdbc" xmlns:pbu="http://www.tibco.com/wrm/policy/pbu" xmlns:pfe="http://xsd.tns.tibco.com/n2/models/pfe/1.0" xmlns:scact="http://xsd.tns.tibco.com/amf/models/sca/componentType" xmlns:scaext="http://xsd.tns.tibco.com/amf/models/sca/extensions" xmlns:service="http://xsd.tns.tibco.com/bx/amx/model" xmlns:smtp="http://xsd.tns.tibco.com/amf/models/sharedresource/smtp" xmlns:soapbt="http://xsd.tns.tibco.com/amf/models/sca/binding/soap" xmlns:startservicefirst="http://www.tibco.com/wrm/policy/startservicefirst" xmlns:threading="http://www.tibco.com/wrm/policy/threading" xmlns:transactedoneway="http://www.tibco.com/wrm/policy/transactedoneway" xmlns:webapp="http://xsd.tns.tibco.com/amf/models/sca/implementationtype/webapp" xmlns:wrm="http://www.tibco.com/wrm" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" compositeext:formatVersion="2" compositeext:version="1.0.0.20180112132229840" name="za.co.rmb.dealamendmentsmaintenance" targetNamespace="http://www.example.com/za.co.rmb.dealamendmentsmaintenance" xmi:id="_4EfRQfeKEeeZRvktH3XIjg" xmi:version="2.0">
<sca:reference multiplicity="0..1" name="WorkListService_Consumer1" promote="dealAmendmentsMaintenanceProcessFlow/WorkListService_Consumer" wiredByImpl="false" xmi:id="_AR2UQPeLEeeZRvktH3XIjg">
<sca:interface.wsdl interface="http://services.brm.n2.tibco.com#wsdl.interface(WorkListService)" scaext:wsdlLocation=".processOut/process/dealAmendmentsMaintenance.xpdl/brm.wsdl" xmi:id="_AR2UQfeLEeeZRvktH3XIjg"/>
</sca:reference>
<sca:reference multiplicity="0..1" name="CreateDailyTasks_Consumer1" promote="dealAmendmentsMaintenanceProcessFlow/CreateDailyTasks_Consumer" wiredByImpl="false" xmi:id="_ATRQkPeLEeeZRvktH3XIjg">
<sca:interface.wsdl interface="http://www.tibco.com/bs3.0/_8uwIINbzEeWTpucOvGErRg#wsdl.interface(CreateDailyTasks)" scaext:wsdlLocation=".processOut/process/dealAmendmentsMaintenance.xpdl/dealAmendments_segregation.wsdl" xmi:id="_ATRQkfeLEeeZRvktH3XIjg"/>
</sca:reference>
</sca:composite>
With ant script i want to extract value in the "interface" attribute under sca:interface, by matching input value in "name" attribute in sca:refernce.
So lets say
if input will be : WorkListService_Consumer1
Expected Output : http://services.brm.n2.tibco.com#wsdl.interface(WorkListService)
Similarly, if
input will be : CreateDailyTasks_Consumer1
Expected Output : http://www.tibco.com/bs3.0/_8uwIINbzEeWTpucOvGErRg#wsdl.interface(CreateDailyTasks)
I tried using various xmltask commands but i am not getting succesfull.
Thanks
Shrijeet Sinha

You almost had the solution, however text() is used to reference the inner text of an XML element, such as <element>This text here</element>. Here is the syntax for referencing an attribute's value:
<xmltask source="xmlfile.xml">
<copy path="sca:composite/sca:reference[#name='${input}']/sca:interface.wsdl/#interface" property="testproperty"/>
</xmltask>

Related

XSLT: how to pass different prefix values for Node and its feilds

I have a requirement where Nodes have a different prefix value where as fields under them has a different prefix, how to achieve this using XSLT. I have attached sample input and expected its output. Can you please advise.
I am expecting nodes have prebix "cac" and its fields as "cbc" and also replace namespace ns2 with r1 prefix.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:StandardBusinessDoc xmlns:ns0="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<ns1:Invoice xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ns1:CustomizationID>urn:cen.eu:en131:2017#compliant#urn:fdc:peppol.eu:2017:pocc:billing:3.0</ns1:CustomizationID>
<ns1:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</ns1:ProfileID>
<ns1:ID>80160238</ns1:ID>
<ns1:BuyerReference>202208_604</ns1:BuyerReference>
<ns1:BillingReference>
<ns1:InvoiceDocumentReference>
<ns1:ID>test</ns1:ID>
<ns1:IssueDate>2022-09-28</ns1:IssueDate>
</ns1:InvoiceDocumentReference>
</ns1:BillingReference>
<ns1:AdditionalDocumentReference>
<ns1:ID>06AB87FD6E1E1EED96F1653A13ADC23</ns1:ID>
<ns1:DocumentDescription>SupplierUID</ns1:DocumentDescription>
</ns1:AdditionalDocumentReference>
<ns1:AdditionalDocumentReference>
<ns1:ID>2M</ns1:ID>
<ns1:DocumentDescription>Series</ns1:DocumentDescription>
</ns1:AdditionalDocumentReference>
<ns2:Classification xmlns:ns2="rl:rl-einvoicing">
<ns2:Line>
<ns2:ID>000010</ns2:ID>
<ns2:VatCategory>
<ns2:VatRate>24</ns2:VatRate>
<ns2:IncomeClassification>
<ns2:Category>category1_2</ns2:Category>
<ns2:Type>E3_561_005</ns2:Type>
<ns2:Amount>112.33</ns2:Amount>
</ns2:IncomeClassification>
</ns2:VatCategory>
</ns2:Line>
</ns2:Classification>
</ns0:StandardBusinessDoc>
Expected Output:
<?xml-model href="http://www.unece.org/fileadmin/DAM/cefact/namespaces/StandardBusinessDocumentHeader/StandardBusinessDocumentHeader.xsd" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<StandardBusinessDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader http://www.unece.org/fileadmin/DAM/cefact/namespaces/StandardBusinessDocumentHeader/StandardBusinessDocumentHeader.xsd" xmlns:rl="rl:rl-einvoicing" xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<cbc:CustomizationID>urn:cen.eu:en131:2017#compliant#urn:fdc:peppol.eu:2017:pocc:billing:3.0</cbc:CustomizationID>
<cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID>80160238</cbc:ID>
<cbc:BuyerReference>202208_604</cbc:BuyerReference>
<cac:BillingReference>
<cac:InvoiceDocumentReference>
<cbc:ID>test</cbc:ID>
<cbc:IssueDate>2022-09-28</cbc:IssueDate>
</cac:InvoiceDocumentReference>
</cac:BillingReference>
<cac:AdditionalDocumentReference>
<cbc:ID>06AB87FD6E1E1EED96F1653A13ADC23</cbc:ID>
<cbc:DocumentDescription>SupplierUID</cbc:DocumentDescription>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>2Μ</cbc:ID>
<cbc:DocumentDescription>Series</cbc:DocumentDescription>
</cac:AdditionalDocumentReference>
<rl:Classification>
<rl:Line>
<rl:ID>000010</rl:ID>
<rl:VatCategory>
<rl:VatRate>24</rl:VatRate>
<rl:IncomeClassification>
<rl:Category>category1_2</rl:Category>
<rl:Type>E3_561_005</rl:Type>
<rl:Amount>112.33</rl:Amount>
</rl:IncomeClassification>
</rl:VatCategory>
</rl:Line>
</rl:Classification>
</StandardBusinessDoc>

Embed image in XML docs

The MSDN page about XML documentation shows that you can write simple things like:
/// <summary>Builds a new string whose characters are the results of applying the function <c>mapping</c>
/// to each of the characters of the input string and concatenating the resulting
/// strings.</summary>
/// <param name="mapping">The function to produce a string from each character of the input string.</param>
///<param name="str">The input string.</param>
///<returns>The concatenated string.</returns>
///<exception cref="System.ArgumentNullException">Thrown when the input string is null.</exception>
val collect : (char -> string) -> string -> string
But can you embed images in your XML documentation?
You can include <img ... /> and other HTML tags in the XML documentation. I just tried this and Visual Studio simply skips over the image (so you will not see it in the IntelliSense) but the fshtmldoc tool in F# Power Pack simply copies the HTML tags to the output HTML document including images.
/// <summary>Hi <img src="http://tomasp.net/img/fpman.jpg" /> there!</summary>
type IMultiKey =
// (...)
Gives me the following generated documentation:
I think the C# compiler does some additional validation of the XML tags, but I do not think this is done in the F# compiler. As an aside, I find writing the XML documents a annoyingly long, so I was playing with using F# Formatting to write them in Markdown instead (but I do not have anything ready yet).

Parsing XML issue

I have been trying to parse an XML file and all is going well except for one thing.
this is what my XML looks like:
<portfolio>
<item>
<image url="http://www.google.com" />
<title>my first title here.</title>
<desc>my first description here...</desc>
<date>15/07/2010</date>
<skills>skills 1, skills 2, skills 3</skills>
</item>
</portfolio>
I have been parsing: title, desc, date, and skills perfectly. The only issue I am having is parsing the image url. I am using this simple parser: https://github.com/robertmryan/Simple-XML-Parser
Anyway this is how I am setting up the element names to parse:
parser.elementNames = #[#"image", #"title", #"desc", #"date", #"skills"];
Anyway what do I feed into the element name for the image url based upon the XML snippet I gave above?
Thanks!
Edit:
I logged the dictionary it returns after trying the following 3 bits of code:
parser.attributeNames = #[#"image url"];
parser.attributeNames = #[#"image"];
parser.attributeNames = #[#"url"];
Each one of those (after being parsed), returns a dictionary which I logged as this:
dict keys: (
title,
skills,
desc,
date
)
So something is not working right.
The image element has a url attribute so you need to specify that you want the attribute to be parsed out too. Do this by setting the value of the attributeNames property on your parser.
This parser is really basic though so it has some limitations. Most important for you is that attributeNames is only used on the 'main' element (specified with rowElementName) so to do what you want to do you will need to edit the parser class to change that.

Find child of child which attribute code is equal to the parameter passed on the url - XSL

On this dynamic website,
The url looks something like this : departments/CHEM.html
CHEM is a parameter.
<xsl:param name="dep" select="'CHEM'" />
a piece of the xml is below
<course acad_year="2012" cat_num="5085" offered="Y">
<term term_pattern_code="1" fall_term="Y" spring_term="N">fall term</term>
<department code="CHEM">
<dept_long_name>Department of Chemistry and Chemical Biology</dept_long_name>
<dept_short_name>Chemistry and Chemical Biology</dept_short_name>
</department>
</course> ....
I am trying to get the dept_short_name to use on my H1 tag, but I have not been successful.So far I tried
<h2><xsl:value-of select="course/department/[code={#$dep}]"/></h2>
Any suggestions??? Thanks!
Just use:
<xsl:value-of select="course/department[#code eq $dep]/dept_short_name"/>
Remember:
In XPath 2.0 (XSLT 2.0) use the eq operator for value comparissons -- it is more efficient than the general comparisson operator = which really, only, needs to be used when at least one of its operands is a sequence.
I would try this:
<xsl:value-of select="course/department[#code=$dep]/dept_short_name/text()"/>
That says: find the department element (inside a course element) whose code attribute is the value of parameter "dep", then find the dept_short_name child element, then get the text inside that element.
You have to use the # to say that "code" is an attribute, but "dep" should not have it. I think the {} notation is for use inside attributes of the non-XSLT elements of your stylesheet, so I wouldn't use it inside a value-of expression.

Problem with BizTalk multi-input map

I have a map that takes 2 input messages, like this:
<ns0:Root>
<InputMessagePart_0>
<root>
<Indicator>1</Indicator>
<NewValue>AAA</NewValue>
</root>
<InputMessagePart_0>
<InputMessagePart_1>
<root>
<Value>BBB</Value>
</root>
<InputMessagePart_1>
</ns0:Root>
(Lots of the nodes are not shown for clarity)
The ouput message looks like this:
<Root>
<Value>AAA</Value>
</Root>
(It's identical to InputMessagePart_1)
If the Indicator is 1, I want Value to be replaced with NewValue. If it's 0, I want Value to stay the same. I used a scripting functoid with code like this:
public string Get_Value(string indicator, string value, string newValue)
{
if(indicator == "1")
{
return newValue;
}
else
{
return value;
}
}
I'm running into problems due to the fact that Value might not actually occur in the original InputMessagePart_1 - if it doesn't, I want to create it. With the script above, even though Indicator is 1, I'm not getting a return string when Value doesn't exist.
Any suggestions?
Updated: I did some further testing by removing the if/then logic and just returned a hard-coded string from the functoid, and I get the same results... it seems that just having the empty input kills the entire functionality of the functoid...
You should want to use the Equal functoid and test whether the value is 1. You'll then feed the result to the input of two functoids:
First, to a Value Mapping functoid, which is connected to the <New Value> tag in the first part of the source schema.
Second, to a Logical Not functoid, which is then connected to another Value Mapping functoid connected to the <Value> tag in the second part of the source schema.
If the <Indicator>; tag does not contain the expected value 1 or is not present in the source message, the Logical Equal functoid will return False, and the second branch of the map will execute.
It doesn't matter whether the Value tag is present in the second part of the source schema. If it is not, either one of the Value Mapping functoids will create it in the destination.
If you definitely need to depend upon the <Indicator> tag, you might want to use the Logical Existence functoid, that returns whether any specified input node appears in the source message.
If all else fails using the mapper, you might try switching to XSLT - see here how to scrape the XSLT out of your existing BTM.
The map that you are after looks straightforward:
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > .. etc ... whatever you've scraped out
<xsl:output ...
<xsl:template match=...>
<ns1:Root>
<ns1:Value>
<xsl:choose>
<xsl:when test="/ns0:Root/ns0:InputMessagePart_0/ns0:root/ns0:Indicator/text()='1'">
<xsl:value-of select="/ns0:Root/ns0:InputMessagePart_0/ns0:root/ns0:NewValue/text()" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/ns0:Root/ns0:InputMessagePart_1/ns0:root/ns0:Value/text()" />
</xsl:otherwise>
</xsl:choose>
<ns1:Value>
</ns1:Root>

Resources