XSLT 1.0 -- 4, XPath string functions
XML document: 004.xml
<? XML version = "1.0"?>
<? XML-stylesheet type = "text/XSL" href = "004.et"?>
<Books>
<Book> abcd12345 </book>
<Name> schema </Name>
<Sub> 123 </sub>
</Books>
XSLT document: 004.xsl
<? XML version = "1.0"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
<XSL: output method = "html" indent = "yes"/>
<XSL: template match = "/books">
<XSL: value-of select = "'book: '"/>
<XSL: value-of select = "book"/>
<XSL: value-of select = "'& # x000a;'"/>
<XSL: value-of select = "'name: '"/>
<XSL: value-of select = "name"/>
<XSL: value-of select = "'& # x000a;'"/>
<XSL: value-of select = "'sub: '"/>
<XSL: value-of select = "sub"/>
<XSL: value-of select = "'& # x000a;'"/>
<! -- Insert the instance code here -->
</XSL: Template>
</XSL: stylesheet>
Shown as follows:
Book: abcd12345 name: schema sub: 123
1. connection string: Concat (string1, string2, string3 ...)
Example:
<XSL: value-of select = "'concat (book,-, name): '"/>
<XSL: value-of select = "Concat (book, '-', name)"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Concat (book,-, name): abcd12345-schema
2. determine the inclusion relationship: Contains (string1, string2)
Note: Determine whether the second string is part of the first string.
Example:
<XSL: value-of select = "'ins ins (book, name): '"/>
<XSL: value-of select = "contains (book, name)"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Contains (book, name): false
3. format the blank space: normalize-space (string)
Note: The white spaces at the header and tail of a string are deleted. If the string contains multiple consecutive white spaces, one space is used instead.
4. Start string: starts-with (string1, string2)
Note: Determine whether the first string starts with the second string.
Example:
<XSL: value-of select = "'starts-with (book, sub): '"/>
<XSL: value-of select = "starts-with (book, sub)"/>
<XSL: value-of select = "'& # x000a;'"/>
<XSL: value-of select = "'starts-with (book, ABC): '"/>
<XSL: value-of select = "starts-with (book, 'abc')"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Starts-with (book, sub): false
Starts-with (book, ABC): True
5. Return String Length: String-length (string)
Note: by default, the string length of the context node is returned.
Example:
<XSL: value-of select = "'string-length (book): '"/>
<XSL: value-of select = "string-length (book)"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
String-length (book): 9
6. truncation string: substring (string, number, length)
Note: String: Specifies the string to be truncated.
Number: Specifies the start position.
Length: Specifies the truncation length.
Example:
<XSL: value-of select = "'substring (book, 1): '"/>
<XSL: value-of select = "substring (book, 1)"/>
<XSL: value-of select = "'& # x000a;'"/>
<XSL: value-of select = "'substring (book, 5, 9): '"/>
<XSL: value-of select = "substring (book, 5, 9)"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Substring (book, 1): abcd12345
Substring (book, 5, 9): 12345
7. Forward truncation string: substring-before (string1, string2)
Note: returns the part of the first string that is located before the second string.
Example:
<XSL: value-of select = "'substring-before (book, sub): '"/>
<XSL: value-of select = "substring-before (book, sub)"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Substring-before (book, sub): ABCD
8. truncate the string backward: substring-after (string1, string2)
Note: returns the part of the first string that is placed after the second string.
Example:
<XSL: value-of select = "'substring-after (book, sub): '"/>
<XSL: value-of select = "substring-after (book, sub)"/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Substring-after (book, sub): 45
9. Replacement character: translate (string, original character, replacement character)
Note: In the string, search for the original character in sequence. If yes, replace it with the replacement character.
Example:
<XSL: value-of select = "'translate (book, sub, name): '"/>
<XSL: value-of select = "translate (book, sub, name)"/>
<XSL: value-of select = "'& # x000a;'"/>
<XSL: value-of select = "'translate (book, sub): '"/>
<XSL: value-of select = "translate (book, sub,'') "/>
<XSL: value-of select = "'& # x000a;'"/>
The output is as follows:
Translate (book, sub, name): abcdsch45
Translate (book, sub): ab45