Specific Problem with escaping quotes in XML/Xpath









up vote
1
down vote

favorite












I have specific problem with some inbound messages that contains quotes(for example) 's-Hertogenbosch and i need to escape the first single quote because i can't inject whole node-set in the DataBase..can anyone tell me solution how can i ignore that quote?..or briefly how at all can i dynamically escape unnecessary quotes in every inbound message except first and last one.



I tryed with translate($InboundMessage, ' " ', "(blankspace)" ) and it worked fine but it removed all quotes..i need to keep first and last one..for example my Inbound message is



'Last year i visited 's-Hertogenbosch '..that single quote makes harm because on the output i got 'Last year i visited' without the name of the city.



Solution?



Regards.










share|improve this question





















  • Are you able to use XSLT 2.0?
    – Tim C
    Nov 10 at 10:34










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    Nov 10 at 10:41










  • You are building the XPath expression in an external tool, right? I'm guessing "TIBCO ActiveMatrix BusinessWorks"? If that's so, does this software offer non-xpath string split and -join functions you can employ to build your expression?
    – Tomalak
    Nov 12 at 9:30














up vote
1
down vote

favorite












I have specific problem with some inbound messages that contains quotes(for example) 's-Hertogenbosch and i need to escape the first single quote because i can't inject whole node-set in the DataBase..can anyone tell me solution how can i ignore that quote?..or briefly how at all can i dynamically escape unnecessary quotes in every inbound message except first and last one.



I tryed with translate($InboundMessage, ' " ', "(blankspace)" ) and it worked fine but it removed all quotes..i need to keep first and last one..for example my Inbound message is



'Last year i visited 's-Hertogenbosch '..that single quote makes harm because on the output i got 'Last year i visited' without the name of the city.



Solution?



Regards.










share|improve this question





















  • Are you able to use XSLT 2.0?
    – Tim C
    Nov 10 at 10:34










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    Nov 10 at 10:41










  • You are building the XPath expression in an external tool, right? I'm guessing "TIBCO ActiveMatrix BusinessWorks"? If that's so, does this software offer non-xpath string split and -join functions you can employ to build your expression?
    – Tomalak
    Nov 12 at 9:30












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have specific problem with some inbound messages that contains quotes(for example) 's-Hertogenbosch and i need to escape the first single quote because i can't inject whole node-set in the DataBase..can anyone tell me solution how can i ignore that quote?..or briefly how at all can i dynamically escape unnecessary quotes in every inbound message except first and last one.



I tryed with translate($InboundMessage, ' " ', "(blankspace)" ) and it worked fine but it removed all quotes..i need to keep first and last one..for example my Inbound message is



'Last year i visited 's-Hertogenbosch '..that single quote makes harm because on the output i got 'Last year i visited' without the name of the city.



Solution?



Regards.










share|improve this question













I have specific problem with some inbound messages that contains quotes(for example) 's-Hertogenbosch and i need to escape the first single quote because i can't inject whole node-set in the DataBase..can anyone tell me solution how can i ignore that quote?..or briefly how at all can i dynamically escape unnecessary quotes in every inbound message except first and last one.



I tryed with translate($InboundMessage, ' " ', "(blankspace)" ) and it worked fine but it removed all quotes..i need to keep first and last one..for example my Inbound message is



'Last year i visited 's-Hertogenbosch '..that single quote makes harm because on the output i got 'Last year i visited' without the name of the city.



Solution?



Regards.







xml xslt xpath tibco






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 16:50









Mihail Mitrevski

255




255











  • Are you able to use XSLT 2.0?
    – Tim C
    Nov 10 at 10:34










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    Nov 10 at 10:41










  • You are building the XPath expression in an external tool, right? I'm guessing "TIBCO ActiveMatrix BusinessWorks"? If that's so, does this software offer non-xpath string split and -join functions you can employ to build your expression?
    – Tomalak
    Nov 12 at 9:30
















  • Are you able to use XSLT 2.0?
    – Tim C
    Nov 10 at 10:34










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    Nov 10 at 10:41










  • You are building the XPath expression in an external tool, right? I'm guessing "TIBCO ActiveMatrix BusinessWorks"? If that's so, does this software offer non-xpath string split and -join functions you can employ to build your expression?
    – Tomalak
    Nov 12 at 9:30















Are you able to use XSLT 2.0?
– Tim C
Nov 10 at 10:34




Are you able to use XSLT 2.0?
– Tim C
Nov 10 at 10:34












Yes,actualy we are using that in Tibco BW
– Mihail Mitrevski
Nov 10 at 10:41




Yes,actualy we are using that in Tibco BW
– Mihail Mitrevski
Nov 10 at 10:41












You are building the XPath expression in an external tool, right? I'm guessing "TIBCO ActiveMatrix BusinessWorks"? If that's so, does this software offer non-xpath string split and -join functions you can employ to build your expression?
– Tomalak
Nov 12 at 9:30




You are building the XPath expression in an external tool, right? I'm guessing "TIBCO ActiveMatrix BusinessWorks"? If that's so, does this software offer non-xpath string split and -join functions you can employ to build your expression?
– Tomalak
Nov 12 at 9:30












1 Answer
1






active

oldest

votes

















up vote
2
down vote













Try this expression....



 <xsl:value-of select='replace($InboundMessage, "(.)&apos;+(.)", "$1$2")'/>


Or, if you want to do it for double quotes...



<xsl:value-of select="replace($InboundMessage, '(.)&quot;+(.)', '$1$2')"/>


EDIT: If you can only use XSLT1.0 and XPATH 1.0, then you have to do some string manipluation



<xsl:value-of select='concat(substring($InboundMessage, 1, 1), translate(substring($InboundMessage, 2, string-length($InboundMessage) - 2), "&apos;", ""), substring($InboundMessage, string-length($InboundMessage)))'/>


Alternatively, given your comment about building SQL, you could just replace all apostrophes, and put the outer apostrophes back in the SQL string you build



<xsl:value-of select='concat("INSERT INTO ", $Destination, " (", $Column, ") VALUES (&apos;", translate($InboundMessage, "&apos;", ""), "&apos;)")'/>





share|improve this answer






















  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    Nov 12 at 9:10










  • I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
    – Mihail Mitrevski
    Nov 12 at 9:13











  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    Nov 12 at 9:23










  • It worked out..thanks :)
    – Mihail Mitrevski
    Nov 12 at 9:52










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230060%2fspecific-problem-with-escaping-quotes-in-xml-xpath%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













Try this expression....



 <xsl:value-of select='replace($InboundMessage, "(.)&apos;+(.)", "$1$2")'/>


Or, if you want to do it for double quotes...



<xsl:value-of select="replace($InboundMessage, '(.)&quot;+(.)', '$1$2')"/>


EDIT: If you can only use XSLT1.0 and XPATH 1.0, then you have to do some string manipluation



<xsl:value-of select='concat(substring($InboundMessage, 1, 1), translate(substring($InboundMessage, 2, string-length($InboundMessage) - 2), "&apos;", ""), substring($InboundMessage, string-length($InboundMessage)))'/>


Alternatively, given your comment about building SQL, you could just replace all apostrophes, and put the outer apostrophes back in the SQL string you build



<xsl:value-of select='concat("INSERT INTO ", $Destination, " (", $Column, ") VALUES (&apos;", translate($InboundMessage, "&apos;", ""), "&apos;)")'/>





share|improve this answer






















  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    Nov 12 at 9:10










  • I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
    – Mihail Mitrevski
    Nov 12 at 9:13











  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    Nov 12 at 9:23










  • It worked out..thanks :)
    – Mihail Mitrevski
    Nov 12 at 9:52














up vote
2
down vote













Try this expression....



 <xsl:value-of select='replace($InboundMessage, "(.)&apos;+(.)", "$1$2")'/>


Or, if you want to do it for double quotes...



<xsl:value-of select="replace($InboundMessage, '(.)&quot;+(.)', '$1$2')"/>


EDIT: If you can only use XSLT1.0 and XPATH 1.0, then you have to do some string manipluation



<xsl:value-of select='concat(substring($InboundMessage, 1, 1), translate(substring($InboundMessage, 2, string-length($InboundMessage) - 2), "&apos;", ""), substring($InboundMessage, string-length($InboundMessage)))'/>


Alternatively, given your comment about building SQL, you could just replace all apostrophes, and put the outer apostrophes back in the SQL string you build



<xsl:value-of select='concat("INSERT INTO ", $Destination, " (", $Column, ") VALUES (&apos;", translate($InboundMessage, "&apos;", ""), "&apos;)")'/>





share|improve this answer






















  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    Nov 12 at 9:10










  • I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
    – Mihail Mitrevski
    Nov 12 at 9:13











  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    Nov 12 at 9:23










  • It worked out..thanks :)
    – Mihail Mitrevski
    Nov 12 at 9:52












up vote
2
down vote










up vote
2
down vote









Try this expression....



 <xsl:value-of select='replace($InboundMessage, "(.)&apos;+(.)", "$1$2")'/>


Or, if you want to do it for double quotes...



<xsl:value-of select="replace($InboundMessage, '(.)&quot;+(.)', '$1$2')"/>


EDIT: If you can only use XSLT1.0 and XPATH 1.0, then you have to do some string manipluation



<xsl:value-of select='concat(substring($InboundMessage, 1, 1), translate(substring($InboundMessage, 2, string-length($InboundMessage) - 2), "&apos;", ""), substring($InboundMessage, string-length($InboundMessage)))'/>


Alternatively, given your comment about building SQL, you could just replace all apostrophes, and put the outer apostrophes back in the SQL string you build



<xsl:value-of select='concat("INSERT INTO ", $Destination, " (", $Column, ") VALUES (&apos;", translate($InboundMessage, "&apos;", ""), "&apos;)")'/>





share|improve this answer














Try this expression....



 <xsl:value-of select='replace($InboundMessage, "(.)&apos;+(.)", "$1$2")'/>


Or, if you want to do it for double quotes...



<xsl:value-of select="replace($InboundMessage, '(.)&quot;+(.)', '$1$2')"/>


EDIT: If you can only use XSLT1.0 and XPATH 1.0, then you have to do some string manipluation



<xsl:value-of select='concat(substring($InboundMessage, 1, 1), translate(substring($InboundMessage, 2, string-length($InboundMessage) - 2), "&apos;", ""), substring($InboundMessage, string-length($InboundMessage)))'/>


Alternatively, given your comment about building SQL, you could just replace all apostrophes, and put the outer apostrophes back in the SQL string you build



<xsl:value-of select='concat("INSERT INTO ", $Destination, " (", $Column, ") VALUES (&apos;", translate($InboundMessage, "&apos;", ""), "&apos;)")'/>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 9:35

























answered Nov 10 at 10:56









Tim C

59.1k126082




59.1k126082











  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    Nov 12 at 9:10










  • I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
    – Mihail Mitrevski
    Nov 12 at 9:13











  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    Nov 12 at 9:23










  • It worked out..thanks :)
    – Mihail Mitrevski
    Nov 12 at 9:52
















  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    Nov 12 at 9:10










  • I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
    – Mihail Mitrevski
    Nov 12 at 9:13











  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    Nov 12 at 9:23










  • It worked out..thanks :)
    – Mihail Mitrevski
    Nov 12 at 9:52















Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
– Mihail Mitrevski
Nov 12 at 9:10




Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
– Mihail Mitrevski
Nov 12 at 9:10












I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
– Mihail Mitrevski
Nov 12 at 9:13





I can inject this node if i use JDBC Update activity when i wrote SQL manualy with question mark and parameters for example 'INSERT INTO Destination (Column) VALUES (?)' and then in the Input just drag and drop the message...but i need to to this dynamic with SQL Direct when i need to wrote all the SQL in one sentence with variables and concatination..for example concat( 'INSERT INTO $Destination ($Column) VALUES ($InboundMessage)').... Look out..in the first example i use regular Values,and in the second example i use Variables..because of that one single quote i can't inject value in DB
– Mihail Mitrevski
Nov 12 at 9:13













I have edited my answer to show an XSLT 1.0 solution
– Tim C
Nov 12 at 9:23




I have edited my answer to show an XSLT 1.0 solution
– Tim C
Nov 12 at 9:23












It worked out..thanks :)
– Mihail Mitrevski
Nov 12 at 9:52




It worked out..thanks :)
– Mihail Mitrevski
Nov 12 at 9:52

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230060%2fspecific-problem-with-escaping-quotes-in-xml-xpath%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo