search for specific text not wrapped within an element - schematron

Hoping someone can help... been trying to figure out how to search for specific text that is not wrapped within an specific element.
The text "FIGURE" can appear anywhere within the XML document. The word FIGURE could also be spelled "Figure"...
This is what I have so far... but its not picking up on the literal text "FIGURE"...
<rule context="text()">
<assert test= "(.,'FIGURE')[not(/GRPHCREF)]" role="error" id="error_grphcref_figure"
>Figure reference not wrapped in GRPHCREF.</assert>
</rule>
Thanks so much for any suggestions...

If you are trying to test whether a text() node contains the word "FIGURE", use the contains() function. To compare case-insensitive, use the upper-case() function, or you could test for contains() with the two literal strings "FIGURE" and "Figure".
The following rule asserts that if a text() node contains the word "FIGURE" (case-insensitive), then it must have a GRPHREC element ancestor.
<rule context="text()[contains(upper-case(.), 'FIGURE')]">
<assert test= "ancestor::GRPHCREF" role="error" id="error_grphcref_figure"
>Figure reference not wrapped in GRPHCREF.</sch:assert>
</rule>
Though I think it would be cleaner to separate value test for the context evaluation and the assertion test, as I have done above. However, below demonstrates how to keep your more general match on all text() nodes and apply all of the conditions within the assert test:
<rule context="text()">
<assert test= "contains(upper-case(.), 'FIGURE') and ancestor::GRPHCREF" role="error" id="error_grphcref_figure"
>Figure reference not wrapped in GRPHCREF.</sch:assert>
</rule>

Related

need xpath where the next descendant that has text is returned

I am trying to write a locator where the next text descendant is returned. I wont know the text. The following xpath works:
//*[#id='myChart']//label[contains(text(),"Show:")]/following::div[4]
but I dont like the div[4] as this could easily change. The element is the first div type descendant under show that contains text. Any suggestions?
A
Considering the following clauses:
the next text descendant
I wont know the text
div[4] as this could easily change
element is the first div type descendant
To locate the element a couple of effective approaches are as follows:
Using xpath:
//*[#id='myChart']//label[contains(., "Show")]//div[text()]
Using xpath with descendant:
//*[#id='myChart']//label[contains(., "Show")]//descendant::div[text()]
Using xpath with following:
//*[#id='myChart']//label[contains(., "Show")]//following::div[text()]
I think this will work for you:
//*[#id='myChart']//label[contains(text(),"Show:")]//div[text()]
To give more confident answer we need to see the actual page / XML.
In case the desired div is a direct child of the label containing the "Show:" the above expression can be presided to
//*[#id='myChart']//label[contains(text(),"Show:")]/div[text()]

regex with OR condition not working in angularjs [duplicate]

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:
.*baidu.com.*[/?].*wd{1}=
I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
but it does not seem to work.
replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).
[] denotes character sets, () denotes logical groupings.
Your expression:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
does need a few changes, including [wd|word|qw] to (wd|word|qw) and getting rid of the redundant {1}, like so:
.*baidu.com.*[/?].*(wd|word|qw)=
But you also need to understand that the first part of your expression (.*baidu.com.*[/?].*) will match baidu.com hello what spelling/handle????????? or hbaidu-com/ or even something like lkas----jhdf lkja$##!3hdsfbaidugcomlaksjhdf.[($?lakshf, because the dot (.) matches any character except newlines... to match a literal dot, you have to escape it with a backslash (like \.)
There are several approaches you could take to match things in a URL, but we could help you more if you tell us what you are trying to do or accomplish - perhaps regex is not the best solution or (EDIT) only part of the best solution?

How to read an XML with libXML2 using no string functions?

Essentially, I have multiple XSD files for a file format, because it's the main method of configuring the program, so I need versions of it with English strings, versions with German strings, etc. And if the file says in its <schema> statement which XSD it's using, it seems like I should be able to go through it without ever making a string comparison.
e.g. I want to avoid doing this:
xmlNodePtr cur = xmlDocGetRootElement(doc);
if(!xmlStrncmp(cur->name, (const xmlChar *) "settings"))
{
// do things
}
Because the string "settings" will change depending on the xsd file used, it could be "paramètres" or "einstellungen," etc. Typically this is done with a separate stings file, but it seems like the xsd has all the information needed to function as that strings file.
However, it's unclear if for example, if the nth attribute in an element is defined by the XSD as optional with a default value, will libxml2 tell me it's the nth attribute, and give it the default value, when I iterate over the properties in the node?
Similarly, it seems like there should be a way to find out that an element is the nth element in the <xs:choice> or the nth item in the <xs:enumeration> but I can't for the life of me figure out how to do it.
e.g. in this enumeration:
<xs:restrict base="xs:string">
<xs:enumeration value="glucose"/>
<xs:enumeration value="fructose"/>
<xs:enumeration value="sucrose"/>
<xs:restrict>
"glucose" would be 0, "fructose" 1, "sucrose" 2, etc in the order that they appear.
Is there a decent way to do this?
Your troubles stem from the design decision that you've made to maintain parallel XSDs with semantically identical components yet lexically different names.
Don't do that.
It's a terrible design decision that'll undermine the benefits of a standard XML vocabulary. Choose a naming convention, including a single natural language, and use it consistently.
Save I18N for the translation of content (see Best Practices for XML Internationalization), not markup.

Difference between replace entire node and replace node contents in OSB

I have recently started using OSB and i came across the feature "replace entire node or replace node contents". Could anyone help me in listing out the difference between the two with examples.
This is a very basic question but i just started learning osb and wanted to get this right.
Thanks in advance.
Cheers..
OK, let's assume you have a variable, $body. Your proxy has done some stuff, and already has $body set, and you want to run it through an xquery transform before you return it.
$body will be something like
<soap:Body xmlns:soap="etc">
<ns0:response xmlns:ns0="etc2">
<ns0:item>
<!-- etc etc -->
</ns0:item>
</ns0:response>
</soap:Body>
If you replace the entire node, you must replace it with a <soap:Body>. (I mean, you could replace it with something different, but you'll encounter an error somewhere because OSB expects $body to be a certain type)
If you replace the node contents, you may replace it with anything: perhaps a transformed <ns0:response>, but it's common to replace it with totally different elements. Either way, the <soap:Body> element is unaffected, and all the insides are scooped out and replaced.
Most of the time, you'll replace node contents of $body rather than replacing the entire node, but if it's a variable you've created yourself, it could go either way depending on what you want.

ibatis dynamic sql using two conditions

I would like to use a dynamic sql statement that executes only when the variable is not null AND greater than zero. Like this:
<isNotNull prepend="AND" property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
but without prepending two 'AND's.
I have read the documentation but have found no good example.
To work around to this issue I almost never use the "prepend" feature, but instead write an sql like this:
WHERE 1=1
<isNotNull property="ProprietaryId">
<isGreaterThan property="ProprietaryId" compareValue="0">
AND G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
I just came across this question while looking for the same answer. While effective, this solution kind of bugged me so I studied the iBATIS docs some more and noticed this example:
<dynamic prepend="where">
<isGreaterThan prepend="and" property="id" compareValue="0">
ACC_ID = #id#
</isGreaterThan>
<isNotNull prepend="and" property="lastName">
ACC_LAST_NAME = #lastName#
</isNotNull>
</dynamic>
You'd think that might cause a superfluous "and" to be included within the WHERE clause if only one of the conditions is true, but apparently iBATIS is smart enough to prevent this when using the dynamic tag. It works for me (using iBATIS 2.3.0 in this case).
Its me from the future. Parent elements override the prepend of their first child, so your code will work fine since the isGreaterThan prepend will be overwritten by the parent isNotNull prepend.
From the docs:
The prepend attribute is a part of the code that is free to be overridden by the a parent element's prepend if necessary. In the above example the "where" prepend will override the first true conditional prepend. This is necessary to ensure that the SQL statement is built properly. For example, in the case of the first true condition, there is no need for the AND, and in fact it would break the statement.
<isNotNull property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
just delete the first prepend will work

Resources