在 XML/Xpath 中转义引号的特定问题 [英] Specific Problem with escaping quotes in XML/Xpath

查看:30
本文介绍了在 XML/Xpath 中转义引号的特定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对一些包含引号的入站消息有特定问题(例如)'s-Hertogenbosch,我需要转义第一个单引号,因为我无法在数据库..谁能告诉我解决方案如何忽略该报价?..或者简单地说,除了第一条和最后一条外,我如何在每条入站消息中动态转义不必要的引号.

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.

我尝试了 translate($InboundMessage, ' " ', "(blankspace)" ) 并且它工作正常但它删除了所有引号..我需要保留第一个和最后一个..例如我的入站消息是

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

'去年我访问了's-Hertogenbosch'..那个单引号有害,因为在输出中我得到了'去年我访问了'而没有城市名称.

'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.

解决方案?

问候.

推荐答案

试试这个表达式....

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')"/>

如果您只能使用 XSLT1.0 和 XPATH 1.0,那么您必须进行一些字符串操作

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)))'/>

或者,根据您对构建 SQL 的评论,您可以替换所有撇号,并将外部撇号放回您构建的 SQL 字符串中

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;)")'/>

这篇关于在 XML/Xpath 中转义引号的特定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆