How to remove specific word with xpath - xpath

I have a piece of code and I can export it with XPath, but I want to remove the specific words from that. this is my sample code
<div class="row mg-none">
<h1>Peppercorn Free Photo</h1>
</div>
this is my XPath
//div[contains(concat (" ", normalize-space(#class), " "), " row mg-none ")]/h1
this gives me "Peppercorn Free Photo" but I want to remove "Free Photo" and I want to output is exactly "Peppercorn"
and also I have to Xpath 1.0

There are several possiblities achieving the same result:
Use substring-before(...) with spaces
substring-before(//div[contains(concat (" ", normalize-space(#class), " "), " row mg-none ")]/h1," ")
Use substring-before(...) with "Free Photo"
normalize-space(substring-before(//div[contains(concat (" ", normalize-space(#class), " "), " row mg-none ")]/h1,"Free Photo"))
Just for the sake of completeness, you could use XPath-2.0 with the fn:replace function to replace the string Free Photo
normalize-space(replace(//div[contains(concat (" ", normalize-space(#class), " "), " row mg-none ")]/h1,"Free Photo",""))
The result in all three cases is
Peppercorn
P.S.:
You can probably reduce your fn:contains(...) expression to
contains(#class, "row mg-none")
instead of
contains(concat (" ", normalize-space(#class), " "), " row mg-none ")

Related

Extract line from multi-line cell that starts with specific character

I have a multi-line cell in A2:
and my goal is to:
extract all lines that start with /
remove in-between empty cells.
My formula in cell B2 is:
=(iferror((ARRAYFORMULA(REGEXEXTRACT(SPLIT(A2,CHAR(10)),"^/.*"))),""))
It is extracting all cells that start with / but keeping empty cell between.
See if this works
=filter(split(A2, char(10)&"/"), regexmatch(split(A2, char(10)), "/.+"))
For an arrayformula you could try
=ArrayFormula(SUBSTITUTE(SPLIT(REGEXREPLACE(A2:A10, "(?:^|\n)([A-Z]+)",), char(10)), "/",))
(Change range to suit)
=ARRAYFORMULA(SUBSTITUTE(SPLIT(TRANSPOSE(QUERY(IFERROR(REGEXEXTRACT(TRANSPOSE(
SPLIT(SUBSTITUTE(A2:A, " ", "♦"), CHAR(10))), "^/(.*)")), , 999^99)), " "), "♦", " "))

Select Case search options

I have an ASP query form that among other things includes a text box which allows the user to enter some text which can be searched for in a database. Unfortunately, the search only returns a result when there is a match for the exact string that was entered. Is there a way to change this so as to return a result for partial matches as well, or if what's in the DB includes all or part of the search string?
The code is below and the Case in question is the one titled "Nam". Note that I have sort of gotten around this issue by adding an asterix wild card feature, but I'd really just prefer to avoid using the asterixes altogether. I chose to leave the extra code for the wildcards out so as not to complicate things.
Select Case strOption
Case "Nam"
strSelect = strSelect & " Nam='" & UCase(strNam) & "'"
Case "Location"
strSelect = strSelect & " Location='" & UCase(strLocation) & "'"
Case "Typ"
strSelect = strSelect & " Typ='" & UCase(strTyp) & "'"
Case "Season"
strSelect = strSelect & " Season='" & UCase(strSeason) & "'"
Case "Duration"
strSelect = strSelect & " Duration='" & UCase(strDuration) & "'"
Case "Yr"
strSelect = strSelect & " Yr='" & UCase(strYr) & "'"
End Select
It's more about SQL than VBScript. According the Operators docs, any of comparison and logical operators return a Boolean data type with a value of TRUE, FALSE, or UNKNOWN. More important could be reading about building a search condition (a combination of one or more predicates) using operators in question; in brief:
= (equal to) is the operator used to test the equality between two expressions;
LIKE indicates that the subsequent character string is to be used with pattern matching and returns TRUE if the operand matches a pattern (more on valid syntax, escaping etc.); a pattern can include the following valid wildcard characters:
% Any string of zero or more characters;
_ (underscore) Any single character;
[] Any single character within the specified range ([a-f]) or set ([abcdef]);
[^] Any single character not within the specified range ([^a-f]) or set ([^abcdef]).
Thus, you could formulate a predicate on Nam in your search condition (in terms of VBScript) as follows:
strSelect = strSelect & " Nam LIKE '%" & UCase(strNam) & "%'"

Oracle Text query rewrite template not working

Why are the two last rewrite rules in the example from Oracle documentation not working?
Source http://docs.oracle.com/cd/B28359_01/text.111/b28303/query.htm#i1007557
Query applications sometimes parse end user queries, interpreting a
query string in one or more ways using different operator
combinations. For example, if a user enters a query of kukui nut, your
application might enter the queries {kukui nut} and {kukui or nut} to
increase recall.
The query rewrite feature enables you to submit a single query that
expands the original query into the rewritten versions. The results
are returned with no duplication.
You specify your rewrite sequences with the query template feature.
The rewritten versions of the query are executed efficiently with a
single call to CONTAINS or CATSEARCH.
The following template defines a query rewrite sequence. The query of
{kukui nut} is rewritten as follows:
{kukui} {nut}
{kukui} ; {nut}
{kukui} AND {nut}
{kukui} ACCUM {nut}
The query rewrite template for these transformations is as follows:
select id from docs where CONTAINS (text,
'<query>
<textquery lang="ENGLISH" grammar="CONTEXT"> kukui nut
<progression>
<seq><rewrite>transform((TOKENS, "{", "}", " "))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", " ; "))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", "AND"))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", "ACCUM"))</rewrite></seq>
</progression>
</textquery>
<score datatype="INTEGER" algorithm="COUNT"/>
</query>')>0;
There's an error in the example provided by Oracle. It is essential that the query operators are separated with spaces:
<seq><rewrite>transform((TOKENS, "{", "}", " AND "))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", " ACCUM "))</rewrite></seq>
so " AND " and " ACCUM " instead of "AND" and "ACCUM" as in the documentation.

Multi-value optional filters with the usage of wildcard in SSRS 2005

I have asked this question before but there are no solution to it. I have created a multivalue filter with the following data-set.
SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, COMPANY_M, CONSECUTIVE_D
FROM TEMP_TARGET
WHERE (CONSECUTIVE_D >= #consecDays) AND (ENTRY_DT BETWEEN #startDate AND #endDate) AND
(ACCESS_LOCATION_X LIKE #accessVar) AND
(IC_N LIKE #icVAr)
It would be relatively easy if the value of my accessVar does not use wildcard but i needed that. So there will be 5 values possible in accessVar:
%(means all), 'At%', 'Bet%', 'Co%' and 'Dea%'
I am unable to use In operator with wildcard. Secondly, can i make this kind of dropdown filters optional? if nth is selected, just query all.
What other options do i have?
You want to use LIKE and multi-value parameters together, which isn't going to work. However, Reporting Services gives us the ability to do almost anything we want. The solution is to use custom code and expressions. First, we change your SQL statement into an expression, like so:
="SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, "
&"COMPANY_M, CONSECUTIVE_D "
&"FROM TEMP_TARGET "
&"WHERE (CONSECUTIVE_D >= #consecDays) "
&"AND (ENTRY_DT BETWEEN #startDate AND #endDate) "
&"AND ((#accessvar IS NULL) OR (ACCESS_LOCATION_X LIKE #accessVar)) "
&"AND ((#icVar IS NULL) OR (IC_N LIKE #icVAr)) "
So now the SQL statement is actually a string expression that will evaluate to a SQL expression which will execute.
Next we need to convert your multi-value parameter into a series of LIKE statements, which we can do with custom code. Add the following custom code to your report (right-click report, select Properties and click the Code tab):
Function AccessLocations (ByVal parameter As Parameter) AS String
Dim Result As String
If parameter.IsMultiValue then
Result = "AND ( "
For i as integer = 0 to parameter.Count-1
Result = Result + "(ACCESS_LOCATION LIKE '" + CStr(parameter.Value(i)) + "') OR "
Next
Result = Left(Result, Result.Length - 3) +") "
Else
Result = "AND (ACCESS_LOCATION LIKE '" + CStr(parameter.Value) + "') "
End If
Return Result
End Function
Then we call this function as part of the SQL statement:
Code.AccessLocations(Parameters!accessvar)
So your full SQL is:
="SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, "
&"COMPANY_M, CONSECUTIVE_D "
&"FROM TEMP_TARGET "
&"WHERE (CONSECUTIVE_D >= #consecDays) "
&"AND (ENTRY_DT BETWEEN #startDate AND #endDate) "
& Code.AccessLocations(Parameters!accessvar)
&"AND ((#icVar IS NULL) OR (IC_N LIKE #icVAr)) "
If your parameter has the % wildcard in it then this will work; otherwise add the wildcard to the function.

Find a part of field using ADODB.Recordset in vb6

I have a table in mdb with field address, which will contain street address e.t.c as string.
I want to be able to search part of this record.
sCriteria = "address like " & "'" & streetAddr & "'"
Rs1.Filter = sCriteria
it searches for e.g "Mall" while there is a record "Mall Road" which should have been found but is not as Road is missing, what should i do to make part of field searchable
Try
sCriteria = "address like '*" & Quote(streetAddr) & "*'"
where Quote does a simple Replace(sText, "'", "''")
Put an '*' before the closing single-quote, after the filter value.

Resources