0

Does anyone know how to select specific character or part in XML value in node?

For example I have value <Country> Holland </Country> or <City>'s-Hertogenbosch</City> and I want to select 'a' character from <Country> and ' (single quote) in <City> without using substring() functions: how can I achieve that? I tried almost everything, but except substring, substring-before, substring-after neither is working.

Armali
  • 18,255
  • 14
  • 57
  • 171
  • You can also use analyze-string and replace function – Navin Rawat Nov 12 '18 at 12:34
  • Your question is not clear. How do you know which character you want to select? Select for what purpose? -- Also, what is the idea of *without using substring() functions*? These functions are integral to XPath/XSLT. If you can't use them, retag your question. – michael.hor257k Nov 12 '18 at 13:07
  • Actually my question is clear..for example i have muliple inbound messages like particular XML format when most of the values in specific nodes have single quotes and i can't inject them in the DB..i can escape those single quotes with backslash '\' but i can do it only manualy with substring functions in every single node..what if i have dozens values with single quotes?..how can i resolve them? – Mihail Mitrevski Nov 12 '18 at 13:38
  • 1
    No, actually your question is a classic [XY problem](http://xyproblem.info/). If you want to escape single quotes, you need to replace them with the escaped string. In XSLT 1.0*, this is done using a named recursive template - see, for example: https://stackoverflow.com/questions/30339128/how-to-replace-single-quote-to-double-single-quote-in-xslt/30339654#30339654 -- (*) I am assuming from [your other question](https://stackoverflow.com/questions/53230060/specific-problem-with-escaping-quotes-in-xml-xpath#comment93402257_53238239) that you cannot use XSLT 2.0. – michael.hor257k Nov 12 '18 at 13:45

2 Answers2

0

I solve this two days ago , first i rendered whole data with render-xml() function and in the output whole node-set is provided as a string..then i split that string with function tokenize() in every single quote character or 'a'..for example tokenize($string, "&amp;") and the in the other variable i put them together like this string-join($tokenize, "\&ampt;")..it seems to work for me...previous i used concat-sequence-format(&tokenize,"\&ampt;") as instead of string i insert a node-set, but obviously is not working (as a node-set)and i don't know why.

0

Is not clear what you are trying to achieve. What you can do is to use the following flow: convert the xml to a clean STRING (uglify it). use a java activity with java Regular Expressions RegExp put the selected words containing the character in a list structure

please give more details of what you are trying to achieve

Andre Leon Rangel
  • 1,659
  • 1
  • 16
  • 28
  • He wants to find characters in a string. The problem is that the information the user is providing in the question is abstracted and is not giving enough detail. I had to deal with some similar issue and the best thing was to sub-string or split. – Andre Leon Rangel Nov 25 '18 at 20:34
  • No, he wants to process XML. – michael.hor257k Nov 25 '18 at 20:51