I have an XSLT statement as follows:
<xsl:when test="address1 != ' '">
My incoming XML the address node is as follows:
<address1/>
The node exists and the xsl statement seems to work sometimes, but it doesn't always work, it is giving me inconsistent results. I am checking the address1 node and if it is spaces, then I check address2 node, if it is not spaces I move it up to address1 output field if address1 input is spaces. Our customers are very inconsistent when entering addresses and our vendor requires address1 to be valid. Thanks for any help.
The problem with checking against a string is that you actually check for text within all descendants of the element, so <foo><bar>test</bar></foo> would fail the test foo = '', because the text test exists within the tree.
A more conclusive test is:
address1[not(text()) and not(*)]
This passes only where there is neither text nor child elements within the address element.
The node is empty.
You are testing for it not being a single space ' ', if it is an empty node the test will succeed.
To test that the node is empty you can do this:
<xsl:when test="address1 = ''">
A self-closing tag should have no content, so checking for '' would be the proper way to go. Doing '[space]' implies that the tag is actually <address1>[space]</address1>, which is no longer self closing.
You're not telling us enough about your code for us to reliably tell you what's wrong with it. Don't be so reticent! There could be all sorts of problems that aren't evident from a tiny snippet, e.g. using the wrong context item.
One piece of advice, though: avoid the "!=" operator (which appeared in your example). Usually you want not(author='') rather than author!=''. They mean the same thing if there is exactly one author element, but they have different meanings if there is no author element or if there is more than one. The expression author!='' is true if there is at least one author element whose value is not the empty string; the expression not(author='') is true if there is no author element whose value is the empty string.
To check if an element's string value is non-empty and non-whitespace-only, use:
string-length(normalize-space(address1)) > 0
The standard XPath function normalize-space($s) takes a string $s as an argument and returns another string produced from $s in which all leading and trailing whitespace characters are removed and any group of adjacent interim whitespace characters is replaced by a single space-character.
This means that the result of normalize-space() when applied on a string that contains only white-space characters, is the empty string (having string-length() of 0).
The XPath expression above is testing if the result of applying the normalize-space() function to the string-value of address1 has positive (> 0) length -- this means that the string value of address1 contains at least one non-whitespace character.
Related
I'm trying to make a multiline comment with this conditions:
Starts with ''' and finish with '''
Can't contain exactly three ''' inside, example:
'''''' Correct
'''''''' Correct
'''a'a''a''''a''' Correct
''''''''' Incorrect
'''a'''a''' Incorrect
This is my aproximation but I'm not able to make the correct expression for this:
'''([^']|'[^']|''[^']|''''+[^'])*'''+
The easy solution is to use a start condition. (Note that this doesn't pass on all your test cases, because I think the problem description is ambiguous. See below.)
In the following, I assume that you want to return the matched token, and that you are using a yacc/bison-generated parser which includes char* str as one of the union types. The start-condition block is a Flex extension; in the unlikely event that you're using some other lex derivative, you'll need to write out the patterms one per line, each one with the <SC_TRIPLE_QUOTE> prefix (and no space between that and the pattern).
%x SC_TRIPLE_QUOTE
%%
''' { BEGIN(TRIPLE_QUOTE); }
<TRIPLE_QUOTE>{
''' { yylval.str = strndup(yytext, yyleng - 3);
BEGIN(INITIAL);
return STRING_LITERAL;
}
[^']+ |
''?/[^'] |
''''+ { yymore(); }
<<EOF>> { yyerror("Unterminated triple-quoted string");
return 0;
}
}
I hope that's more or less self-explanatory. The four patterns inside the start condition match the ''' terminator, any sequence of characters other than ', no more than two ', and at least four '. yymore() causes the respective matches to be accumulated. The call to strndup excludes the delimiter.
Note:
The above code won't provide what you expect from the second example, because I don't think it is possible (or, alternatively, you need to be clearer about which of the two possible analyses is correct, and why). Consider the possible comments:
'''a'''
'''a''''
'''a''''a'''
According to your description (and your third example), the third one should match, with the internal value a''''a, because '''' is more than three quotes. But according to your second example (slightly modified), the second one should match, with the internal value ', because the final ''' is taken as a terminator. The question is, how are these two possible interpretations supposed to be distinguished? In other words, what clue does the lexical scanner have that in the second one case, the token ends at ''' while in the third one it doesn't? Since both of these are part of an input stream, there could be arbitrary text following. And since these are supposed multi-line comments, there's no apriori reason to believe that the newline character isn't part of the token.
So I made an arbitrary choice about which interpretation to choose. I could have made the other arbitrary choice, but then a different example wouldn't work.
From the example, the name of the processor is returned but with a space at the end, how can I make it return a value without a space in the end?
[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic cpu get Name
OutputType=ANSI
RegExpSubstitute=1
Substitute="Name.*#CRLF#":"","#CRLF#":""
ClipString=1
IfCondition=1
IfTrueAction=[!CommandMeasure MeasureRun "Run"]
[MeterResult]
Meter=String
MeasureName=MeasureRun
FontSize=14
FontColor=255,255,255,255
AntiAlias=1
Text=%1!
I think this can be done through regular expression, but I'm not strong at it.
Just add another Substitute in the substitution list to replace the occurence of one or more whitespaces from the end of the string (the pattern "\s+$") with an empty string like below:
Substitute="Name.*#CRLF#":"","#CRLF#":"","\s+$":""
i have a issue where the there is a amount field which has data like
(- 98765.00),minus{spaces]{numbers} ?, i need to remove the space between the minus and the number and get is as (-98765.00), how do i do it in expression transformation.
field datatype is decimal (8,2).
Thanks,
Kiran
output_port: TO_DECIMAL(REPLACECHR(FALSE,input_port,' ',''))
REPLACECHR replaces the blanks with empty character, essentially removing them. The first argument can be TRUE/FALSE to specify case sensitive or not, but it is not important in this case.
You can use REG_REPLACE function to replace space
To achieve this you need to follow below steps,
* Create two variable ports
* REG_REPLACE - function requires string column, so you need to convert the decimal column to string column using TO_CHAR function
First variable port(string) - TO_CHAR(column_name)
* In previous port data is converted to string, now convert it again to decimal and apply REG_REPLACE function
Second variable port(decimal) - to_decimal(reg_replace(first_variable_port,'s+',''))
s - determines the white spaces in informatica regular expression
See the below image,
same number which you provided is used. Use the same data type and function
Debugger gives the exact result by removing white space in the below image,
May be you have the issue with other transformations which you are passing through. Debug and verify the data once.
Hope you got it, any issues feel free to ask
To have enjoy informatica, have a fun on https://etlinfromatica.wordpress.com/
If my understanding is correct, you need to replace both the spaces and the brackets. Here's the expression:
TO_DECIMAL(
REPLACECHR(0,
REPLACECHR(0, '(- 98765.00)', ' ', '') -- this part does the space replacement
, '()', '') -- this part replaces the brackets
)
Given a directory tree, how would I go about cutting the last field of the delimiter out of the string and returning the string without that delimiter, assuming I don't know where that string ends?
For instance, given
/1/2/3/4/5
I know I can return 5 with
cut -f 5 -d '/'
if I know the last field is the 5th one, or if a=/1/2/3/4/5
echo ${a##*/}
to pick the last field. But how would I go about returning the original string minus the last field? ie
/1/2/3/4
You can use the % or %% operator instead of ##. From the Bash man-page:
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expan-
sion. If the pattern matches a trailing portion of the expanded value
of parameter, then the result of the expansion is the expanded value of
parameter with the shortest matching pattern (the ``%'' case) or the
longest matching pattern (the ``%%'' case) deleted. If parameter is #
or *, the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list. If parame-
ter is an array variable subscripted with # or *, the pattern removal
operation is applied to each member of the array in turn, and the
expansion is the resultant list.
In short, ${a%/*} will do the trick.
You can give cut a range of fields
cut -f 1-4 -d '/'
I have one requirement related to XSLT.
i want to remove ending alphabets in my final output string.
here is the example:
Input string:0123467AAA
Output :0123467
i.e no ending alphbets.
i m new to xslt creation,any suggestion is very helpful to me.
Thank you all in advance.
With XSLT 1.0 your only real option for this is to write a recursive template. Write a named template that takes the string as a parameter. Test whether the last character is a letter. (You can find the last character by using substring($s, string-length($s)-1, 1), and you can test whether it is a letter by testing translate($s, 'ABCD..XYZ', '') = ''). If the last character is a letter make a recursive call to your template passing the whole string minus the last character as the value of the parameter (again, by using substring()). Otherwise, return the string. Make sure that your recursion terminates if the string is zero length.