I 'm wring Xpath scripts using concat function to display the result in lines using XPath 1.0
XML example
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XPath
concat("To : ", /note/to , ' \n ', "From : ", /note/from, ' \n ', "Heading : ", /note/heading, ' \n ', "Body : ", /note/body)
Result
To : Tove \n From : Jani \n Heading : Reminder \n Body : Don't forget me this weekend!
However when I use the concat with two element and "\n" in between it works fine.
xPath:
concat("To : ", /note/to , ' \n ', "From : ", /note/from)
Result:
To : Tove
From : Jani
XPath doesn't recognise backslash as an escape character. "\n" simply represents the two characters "backslash, 'n'", it doesn't represent a newline.
If your XPath expression is embedded in a host language such as Java or C#, then the host language will convert \n to newline before the XPath engine ever sees it. But you don't say anything about the host language in which the expressions appear.
If your XPath expression appears within XSLT or XQuery, then you should write a newline as
or . If it's some other environment, then you can use a literal newline.
So the answer is, it all depends on the host environment in which you are writing these expressions.
Related
I'm trying to replace all single quotation marks with double quotation marks in Clojure. i.e. if the string id " 'name' " I want it to become " "name" ". How can I do that?
I've been trying to use the replace function like this:
(clojure.string/replace " 'The color is red' " #"'" """)
but it is not working.
You've forgotten to escape the double quotation mark
(clojure.string/replace " 'The color is red' " #"'" "\"")
I do this so often I made some convenience functions:
quotes->double
quotes->single
You can find the details here. You may also find this template project useful, esp. the documentation list at the end.
How do you use Text() with a format that has a string inside it ?
=TEXT(A1,"Comfi+"#0"(JO)";"Comfi-"#0"(JO)")
Tried """ both the inner string :
=TEXT(A1," """Comfi+"""#0"""(JO)""";"""Comfi-"""#0"(JO)""" ")
Same result with &char(34)&
Similar issue here, but I couldn't transpose the solution to my problem : How to create strings containing double quotes in Excel formulas?
Post Solution edit :
Building an almanac/calendar with the following (now fixed)formula :
=CONCATENATE(
TEXT(Format!K25,"d"),
" J+",
Format!S25,
" ",
TEXT(Format!AA25,"""Comfi+""#0""(JO)"";""Comfi-""#0""(JO)"""),
" ",
Format!AI25
)
Giving the following output in each cell :
9
J+70
Comfi+21(JO)
CRG
You've got too many quotation marks inside:
=TEXT(A1,"""Comfi+""#0""(JO)"";""Comfi-""#0""(JO)""")
You were tripling many of the inside quotation marks.
Personally, doubling up double-quotes within a quoted string is something I try to avoid at all costs. You can 'escape' the text into literals with a backslash.
=TEXT(A1,"\C\o\m\f\i+#0\(\J\O\);\C\o\m\f\i-#0\(\J\O\)")
'alternately
="Comfi"&text(a1, "+#0;-#0")&"(JO)"
Not all of those actually need to be escaped; only reserved characters. However, I usually escape them all and let Excel sort them out.
I have some hotels that contains characters which are not valie for when i want to insert these hotel names as a file name as file naming doesn't allow /, * or ? and want to know what this error means.
text?text
text?text
text**text**
text*text (text)
text *text*
text?
I am trying to use an if else statement so that if a hotel name contains any of these characters, then replace them with -. However I am receiving and error stating a dangling ?. I just want to check if I am using the replace correctly for these characters.
def hotelNameTrim = hotelName.toString()
if (hotelNameTrim.contains("/"))
{
hotelNameTrim.replaceAll("/", "-")
}
else if (hotelNameTrim.contains("*"))
{
hotelNameTrim.replaceAll("*", "-")
}
else if (hotelNameTrim.contains("?"))
{
hotelNameTrim.replaceAll("?", "-")
}
replaceAll accepts a regex as a search pattern. * and ? are special characters in regex and need to be escaped with a back slash. Which itself needs to be escaped in a Java string :)
Try this:
hotelNameTrim.replaceAll("[\\*\\?/]","-")
That will replace all you characters with a dash.
I want to write a xquery statement that returns a number plus a string called " books". Like this:
<table>
<tr><td>300 books</td></tr>
<tr><td>145 books</td></tr>
</table>
I've started writing the code, but it doesn't work...
<tr><td>{$num + 'books'}</td>
Any help with this?
Move the literal string " books" outside of the expression:
<tr><td>{$num} books</td></tr>
Or you could create a sequence of items by enclosing it inside of parenthesis and separating with a comma:
<tr><td>{($num, 'books')}</td></tr>
Or you could concatenate the items (notice the leading space):
<tr><td>{concat($num, ' books')}</td></tr>
I am using Escaping Strings in XPath.
My String in XML File is :
"Test ' both " quotes"::LGC"
So I converted it into XPath strings :
Value[#Name=\"concat(\"Test ' both \",'\" quotes\"::LGC')\"]
But still MSXML Select Single Node return me E-FAIL.
Any idea what I am missing XPath strings ?