Xpath multiply formatted output - xpath

Have a many entries in an xml file and have xpath with condition:
/XMLReport/Report/PreflightResult/PreflightResultEntry[
#type = 'Check' and #level = 'warning']/PreflightResultEntryMessage/Message/text()
The output is:
onetwothreefour... and more
I need separation
'---' one---two---three---four
or
[enter]
one
two
three
four
Its possible ?

Why you bound XPath expression inside single quote ':
Use this:
string-join(/XMLReport/Report/PreflightResult/PreflightResultEntry[#type = 'Check' and #level = 'warning']/PreflightResultEntryMessage/Message/text(), '---')

Your XPath expression is actually returning a set of text nodes. The way these are displayed depends on the calling application (which you haven't told us anything about). I think your options are (a) change the way the calling application displays the result, or (b) if you're using XPath 2.0+, use the string-join() function to return the result as a string, formatted any way you like within the XPath expression itself.

Related

Easy way to transform XPath with contains to equals check?

Is there an easy way to transform an XPath query (as string), like:
my/x/path[contains(sub/path, 'text')]
to an XPath query which uses equals instead of contains? Such that I can easily use the same query, one time with contains and another time with equals? Unfortunately there is no "equals" function in XPath...
You might differentiate between the two options via a flag:
my/x/path[ ($wantContains and contains(sub/path, 'text'))
or
(not($wantContains) and sub/path = 'text')
]

Tibco - Compare values activity

Let's say I have a value that is passed to a process. What activity should i use to compare this value with another?
I know it may seem a foolish question, but i am new to this.
Assuming you are talking about BusinessWorks, comparing text values of XML attributes or elements is done with XPath using the '=' sign. You don't need to use any specific activity to do so. This can actually be done on any branch (with the "Success with condition" switch) or on the input tab of any activity.
For instance, if you want to compare the text values of 2 elements, you can use an XPath formula like this:
$Start/root/myString1 = $Start/root/myString2
This formula returns true if myString1 and myString2 have the same text value, false otherwise.
Then you can, for example, use this formula as a test condition for an "If" or a "Choice" statement on an input tab of any activity.

Unary NOT operator in Oracle text search

I am trying to compose a text search query which would return records containing a certain value in one section and NOT containing a certain value in another section.
Something like that:
SELECT * FROM text_search_table WHERE (contains(text_search,
'(value1 within section1) AND (NOT(value2) within section2)') > 0)
The syntax of this query is incorrect since NOT operator requires two operands. I also tried using % as the first operand:
% NOT value2 within section2
It doesn't work either.
Is there a way in text search to achieve what I need?
Thank you.
I'm fairly certain (not 100%) that you can't use the NOT operator with the WITHIN in the manner you want to. The standard way might be to do the following instead:
select *
from text_search_table
where contains(text_search, 'value1 within section1') > 0
and not contains(text_search, 'value2 within section2') > 0
However, you can cheat this slightly. If you know that some text appears in the second section you can utilise the NOT operator to search for that and NOT the thing you're looking for:
select *
from text_search_table
where contains(text_search
, 'value1 within section1 and (known_value not value2) within section2') > 0
As the known value exists it's always within the section. If value2 is within the section then nothing is returned; if it it's not within the section then the condition is false and you retrieve it.

Problem running xpath query with namespaces

I'm trying to use an xpath expression to select a node-set in an xml document with different namespaces defined.
The xml looks something like this:
<?POSTEN SND="SE00317644000" REC="5566420989" MSGTYPE="EPIX"?>
<ns:Msg xmlns:ns="http://www.noventus.se/epix1/genericheader.xsd">
<GenericHeader>
<SubsysId>1</SubsysId>
<SubsysType>30003</SubsysType>
<SendDateTime>2009-08-13T14:28:15</SendDateTime>
</GenericHeader>
<m:OrderStatus xmlns:m="http://www.noventus.se/epix1/orderstatus.xsd">
<Header>
<OrderSystemId>Soda SE</OrderSystemId>
<OrderNo>20090811</OrderNo>
<Status>0</Status>
</Header>
<Lines>...
I want to select only "Msg"-nodes that has the "OrderStatus" child and therefore I want to use the following xpath expression: /Msg[count('OrderStatus') > 0] but this won't work since I get an error message saying: "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function".
So I think I want to use an expression that looks something like this: /*[local-name()='Msg'][count('OrderStatus') > 0] but that doesn't seem to work.. any ideas?
Br,
Andreas
I want to use the following xpath
expression:
/Msg[count('OrderStatus')[ 0]
but this won't work since I get an error message saying: "Namespace
Manager or XsltContext needed.
This is a FAQ.
In XPath a unprefixed name is always considered to belong in "no namespace".
However, the elements you want to select are in fact in the "http://www.noventus.se/epix1/genericheader.xsd"
namespace.
You have two possible ways to write your XPath expression:
Use the facilities of the hosting language to associate prefixes to all different namespaces to which names from the expression belong. You haven't indicated what is the hosting language in this concrete case, so I can't help you with this. A C# example can be found here.
If you have associated the prefix "xxx" to the namespace "http://www.noventus.se/epix1/genericheader.xsd" and the prefix "yyy" to the namespace "http://www.noventus.se/epix1/orderstatus.xsd", then your Expression can be written as:
/xxx:Msg[yyy:OrderStatus]
:2: If you don't want to use any prefixes at all, an XPath expression can still be constructed, however it will not be too readable:
/*[local-name() = 'Msg' and *[local-name() = 'OrderStatus']]
Finally, do note:
In order to test if an element x has a child y it isn't necessary to test for a positive count(y). Just use: x[y]
Xpath positions are 1-based. This means that NodeSetExpression[0] never selects a node. You want: NodeSetExpression[1]

XPath concat multiple nodes

I'm not very familiar with xpath. But I was working with xpath expressions and setting them in a database. Actually it's just the BAM tool for biztalk.
Anyway, I have an xml which could look like:
<File>
<Element1>element1<Element1>
<Element2>element2<Element2>
<Element3>
<SubElement>sub1</SubElement>
<SubElement>sub2</SubElement>
<SubElement>sub3</SubElement>
<Element3>
</File>
I was wondering if there is a way to use an xpath expression of getting all the SubElements concatted? At the moment, I am using:
/*[local-name()='File']/*[local-name()='Element3']/*[local-name()='SubElement']
This works if it only has one index. But apparently my xml sometimes has more nodes, so it gives NULL. I could just use
/*[local-name()='File']/*[local-name()='Element3']/*[local-name()='SubElement'][0]
but I need all the nodes. Is there a way to do this?
Thanks a lot!
Edit: I changed the XML, I was wrong, it's different, it should look like this:
<item>
<element1>el1</element1>
<element2>el2</element2>
<element3>el3</element3>
<element4>
<subEl1>subel1a</subEl1>
<subEl2>subel2a</subEl2>
</element4>
<element4>
<subEl1>subel1b</subEl1>
<subEl2>subel2b</subEl2>
</element4>
</item>
And I need to have a one line code to get a result like: "subel2a subel2b";
I need the one line because I set this xpath expression as an xml attribute (not my choice, it's specified). I tried string-join but it's not really working.
string-join(/file/Element3/SubElement, ',')
/File/Element3/SubElement will match all of the SubElement elements in your sample XML. What are you using to evaluate it?
If your evaluation method is subject to the "first node rule", then it will only match the first one. If you are using a method that returns a nodeset, then it will return all of them.
You can get all SubElements by using:
//SubElement
But this won't keep them grouped together how you want. You will want to do a query for all elements that contain a SubElement (basically do a search for the parent of any SubElements).
//parent::SubElement
Once you have that, you could (depending on your programming language) loop through the parents and concatenate the SubElements.

Resources