String with XSL

xiaoxiao2021-03-05  55

People who are familiar with XPath know that using the Translate function in XSL can replace a string. E.g:

Translate ("Bar", "ABC", "ABC") will get bar

Translate ("- AAA -", "ABC -", "ABC") will get AAA.

However, if you want to replace a sub-string as another sub-string, in terms of xpath1.0, it is a bit force that use translate.

In general, there are two methods for string in XSL:

(1) Use MS: Script to embed XSL implementation, but as required by the XML parser must be MS.

(2) Use the pure XSL template to achieve.

Of course, there is a benefit using subsection (1) to make full use of the JavaScript powerful string processing function, for example, a regular expression can also be used. A pure XSL template is used here to implement a string replacement. The source code is as follows, where the following part is an example for testing:

string replacement function
source string fromString < / TH> TOSTRING Replacement result

XML used to test:

asdflaksdjfalsdkfjaslkdjf a bb < S> asdflaksdjfalsdkfjaslkdjf flaksdjfals bbb asdflaksdjfalsdkfjaslkdjf DJFA < To> BBB asdflaksdjfalsdkfjaslkdjf sdf vvv I am not Sichuan Sichuan Chongqing select * from table where a a = b = * =

Conversion results:

Character string replacement function

Replace the source string FromStringToString result asdflaksdjfalsdkfjaslkdjfabbbbbbsdflbbbksdjfbbblsdkfjbbbslkdjfasdflaksdjfalsdkfjaslkdjfflaksdjfalsbbbasdbbbdkfjaslkdjfasdflaksdjfalsdkfjaslkdjfdjfabbbasdflaksbbblsdkfjaslkdjfasdflaksdjfalsdkfjaslkdjfsdfVVVaVVVlaksdjfalsdkfjaslkdjf I am not a native of Sichuan, Chongqing, Sichuan, Chongqing I am not a man SELECT * FROM TAble where a = b = * = SELECT * FROM TAble where a * = b

转载请注明原文地址:https://www.9cbs.com/read-34608.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.037, SQL: 9