Specific Problem with escaping quotes in XML/Xpath











up vote
0
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
    2 days ago










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    2 days ago










  • 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
    16 hours ago















up vote
0
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
    2 days ago










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    2 days ago










  • 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
    16 hours ago













up vote
0
down vote

favorite









up vote
0
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

204




204












  • Are you able to use XSLT 2.0?
    – Tim C
    2 days ago










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    2 days ago










  • 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
    16 hours ago


















  • Are you able to use XSLT 2.0?
    – Tim C
    2 days ago










  • Yes,actualy we are using that in Tibco BW
    – Mihail Mitrevski
    2 days ago










  • 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
    16 hours ago
















Are you able to use XSLT 2.0?
– Tim C
2 days ago




Are you able to use XSLT 2.0?
– Tim C
2 days ago












Yes,actualy we are using that in Tibco BW
– Mihail Mitrevski
2 days ago




Yes,actualy we are using that in Tibco BW
– Mihail Mitrevski
2 days ago












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
16 hours ago




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
16 hours ago












1 Answer
1






active

oldest

votes

















up vote
1
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
    17 hours ago










  • 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
    17 hours ago












  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    16 hours ago










  • It worked out..thanks :)
    – Mihail Mitrevski
    16 hours ago











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
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
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
    17 hours ago










  • 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
    17 hours ago












  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    16 hours ago










  • It worked out..thanks :)
    – Mihail Mitrevski
    16 hours ago















up vote
1
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
    17 hours ago










  • 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
    17 hours ago












  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    16 hours ago










  • It worked out..thanks :)
    – Mihail Mitrevski
    16 hours ago













up vote
1
down vote










up vote
1
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 16 hours ago

























answered 2 days ago









Tim C

59.1k126082




59.1k126082












  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    17 hours ago










  • 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
    17 hours ago












  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    16 hours ago










  • It worked out..thanks :)
    – Mihail Mitrevski
    16 hours ago


















  • Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
    – Mihail Mitrevski
    17 hours ago










  • 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
    17 hours ago












  • I have edited my answer to show an XSLT 1.0 solution
    – Tim C
    16 hours ago










  • It worked out..thanks :)
    – Mihail Mitrevski
    16 hours ago
















Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
– Mihail Mitrevski
17 hours ago




Still is not working..Unfortunately replace() function don't exist in Tibco BW XSLT
– Mihail Mitrevski
17 hours ago












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
17 hours ago






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
17 hours ago














I have edited my answer to show an XSLT 1.0 solution
– Tim C
16 hours ago




I have edited my answer to show an XSLT 1.0 solution
– Tim C
16 hours ago












It worked out..thanks :)
– Mihail Mitrevski
16 hours ago




It worked out..thanks :)
– Mihail Mitrevski
16 hours ago


















 

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




















































































Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation