The use of SUBSTRING functions in XSLT

Source: Internet
Author: User
Tags xsl xslt

1. function definition :

String substring (string, number, number?)

substring function function in 2.xslt :

Returns a substring of the first parameter, starting at the position specified by the second argument, and the length specified by the third argument. The length subscript starts from 1.

Attention:

Each character in the string is considered to have a numeric position: the position of the first character is 1, the position of the second character is 2, and so on.

If you do not specify a third argument, the substring that starts at the position specified by the second argument until the end of the string is returned.

If the argument is not a string type, it is first converted to a string using the string () function, and then the result of the transformation is computed.

This function is case-sensitive.

Small example:

(1) substring ("12345", 2, 3) return: 234
(2) substring ("12345", 2)   return: 2345

The substring returned contains the following characters: the character position is greater than or equal to the rounding value of the second parameter, and if the third argument is specified, the sum of the rounded values of the second and third parameters is less than. The comparisons and additions used above follow the IEEE 754 Standard rules and are rounded as if the round () function is called.

The following example illustrates an exception condition.

substring ("12345", 1.5, 2.6) return "234"

substring ("12345", 0, 3) return "

substring ("12345", 0 div 0, 3) returns ""

substring ("12345", 1, 0 div 0) returns ""

substring ("12345", -42, 1 Div 0) return "12345"

substring ("12345",-1 Div 0, 1 Div 0) return ""

Demo substring () expression

XSLT file (substring.xsl)
<?XmlVersion=‘1.0‘?><Xsl:StylesheetVersion="1.0"Xmlns:xsl="Http://www.w3.org/1999/XSL/Transform"><Xsl:TemplateMatch="/"> substring ("12345", 2, 3) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", 2, 3)‘/><Br/> substring ("12345", 2) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", 2)‘/><Br/> substring ("12345", 1.5, 2.6) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", 1.5, 2.6)‘/><Br/> substring ("12345", 0, 3) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", 0, 3)‘/><Br/> substring ("12345", 0 div 0, 3) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", 0 div 0, 3)‘/><Br/> substring ("12345", 1, 0 div 0) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", 1, 0 div 0)‘/><Br/> substring ("12345", -42, 1 div 0) =<Xsl:value-ofSelect=‘SUBSTRING ("12345", -42, 1 Div 0)‘/> <br/> substring (" 12345 ", 1 Div 0, 1 div 0) = xsl :value-of select= substring ("12345",-1 Div 0, 1 Div 0)  ' 
Formatted output

SUBSTRING ("12345", 2,3) = 234 substring ("12345", 2) = 2345 substring ("12345", 1.5, 2.6) = 234 substring ("12345", 0, 3) = 12 SUBSTRING ("12345", 0 div 0, 3) = substring ("12345", 1, 0 div 0) = substring ("12345", -42, 1 div 0) = 12345 substring ("1234 5 ",-1 Div 0, 1 div 0) =

< Span style= "color:blue;" > < Span style= "color:blue;" > < Span style= "color:blue;" > &NBSP;             
Processor Output XML
<?XmlVersion="1.0"?> substring ("12345", 2, 3) = 234<Br/> substring ("12345", 2) = 2345< br /> substring ("12345", 1.5, 2.6) = 234<br /> substring ("12345", 0, 3) = 12<br /> substring ("12345", 0 div 0, 3) = <br /> substring ("12345", 1, 0 div 0) = <br /> substring ("12345", -42, 1 div 0) = 12345<br /> substring ("12345",-1 Div 0, 1 div 0) =  span>                 
< Span style= "color:blue;" > < Span style= "color:blue;" > < Span style= "color:blue;" >  
/span>





The use of SUBSTRING functions in XSLT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.