Function Library
Variables
Examples
funtions used to maniuplate the XPath
Can be used for a node-test or a predicate
All functions use
return-type function-name(parameters)
return-type
  • object function-name(parameters)
  • string function-name(parameters)
  • number function-name(parameters)
  • node-set function-name(parameters)
  • parameters
  • type function-name(parameters)
  • ? means the parameter is optional
  • + means the parameter can occur multiple times
  • object means any type can be passed
  • * selects all nodes
    boolean boolean( object )

    converts anything passed to it to a boolean

    example

    • boolean (attribute::name)
      • will return true of the context node has a name attribute
    • numbers return true if they are not zero or NaN
    • strings are true if length is non-zero
    • node-sets are true if they are not empty
    number ceiling( number ) rounds a passed number to the smallest integer that is not smaller than the passed number

    example

    • ceiling (1.3)
      • will return a 2
    comment() gets the comments for that element
    string concat( string1, string2+) concats all strings passed into one string

    example

    • concat ("con", "c", "a", "t" )
      • will return concat
    boolean contains( string1, string2 ) returns true if string1 contains string2

    example

    • concat ("con", "c" )
      • will return true
    number count( node-set ) returns the number of nodes in the passed node-set

    example

    • count(child::*[@name])
      • will return the number of child elements of the context node that have a name attribute
    boolean false() always returns false, xpath does not have a true or false literal value

    example

    • starts-with( @name, 'T' ) = false()
      • used insted of false
    number floor( number ) rounds a passed number to the largest integer that is not larger than the passed number

    example

    • floor (2.9)
      • will return a 2
    • floor (-1.1)
      • will return a -2
    node-set id( string ) matches the id inside the parenthesis
    only works in validated documents, because that's where you get attributes that are id values
    boolean lang() returns true if the language of the context node is the same as the passed language parameter
    boolean last( string ) returns the index number of the last node in the current node-set

    example

    • child::*[position() = last()-1]
      • returns the index of the last child element of the context node
    literal name ie: person::text()?????
    returns true for all nodes <person> if the node test is "person" (if the type is an element)
    string local-name( nodeset? ) returns the local part of the name of the first node in the passed node-set, if no nodeset is passed, the current context node is used

    example

    • <xsl:value-of>
      • the element is value-of
    string name( nodeset? ) returns the the name of the first node in the passed node-set, if no nodeset is passed, the current context node is used

    example

    • <xsl:value-of>
      • the name is xsl:value-of
    string namepace-uri( nodeset? ) returns the the URI of the first node in the passed node-set, if no nodeset is passed, the current context node is used

    example

    • child::[namespace-uri(@href)]
      • the value might return "http://www.w3.org/Profiles/XHTML-transitional"
    string normalize-space( string? ) returns the the whitespace-normalized version of the passed string

    example

    • normalize-space(     "     some      text    ")
      • would return "some text"
    node() returns true for all nodes except attributes and namespaces
    boolean not() returns the inverse of the passed value

    example

    • not(@name)
      • would return true if there is no name attribute on the context node
    number number( object? ) converts a parameter to a number, if nothing is passed, the current context node is used

    example

    • number ("      -3.67      ")
      • would return -3.67
    number position() gets the position of the current notext node-set
    returns 1 for the first node in the context node-set
    processing-instruction( name? ) true for all processing instruction nodes (no parameters are necessary), but the parameters must match, if you are testing for that, and does the processsing-instruction
    number round( number ) rounds a passed number to the nearest integer value

    example

    • round(-1.7)
      • returns -2
    string starts-with( string1, string2 ) returns true if string1 starts with string2 value

    example

    • starts-with( @name, 'T' )
      • true if the attribute "name" starts with a "T"
    string string( object? ) converts the passed object to a string value, if nothing is passed, the result is an empty string
    string string-length( string? ) returns the number of characters in the passed string

    example

    • string-length( "hello world" )
      • returns 11
    string substring( string, number1, number2 ) returns the substring between the two numbers passed. (starts at the first number, and goes to the length of number2) If no number2 is passed, starts at the number1 and returns the string till the end of the passed string

    example

    • susbstring( "Mount Zion", '7' )
      • returns "Zion"
    string substring-after( string1, string2 ) returns the substring following the first occurence of string2 inside string1

    example

    • substring-after( "2000/3/22", "/" )
      • returns "3/22"
    string substring-before( string1, string 2) returns the substring preceding the first occurence of string2 inside string1

    example

    • substring-before( "2000/3/22", "/" )
      • returns "2000"
    number sum( node-set ) returns the sum of allthe nodes in the set

    example

    • sum( student/@score )
      • returns the sum of all score attributes on the student elements for the axis given
    string text( string ) gets the text
    string translate( string1, string2, string3) string1 is the string to be changed
    string2 defines which characters to be changed
    string3: what those characters should be changed to

    example

    • translate( "abcdefg", "cdeg", "CDE")
      • returns "abCDEf"
        "G" gets dropped because it's listed in string2 and dropped in string3
    boolean true() always returns true, xpath does not have a true or false literal value

    example

    • starts-with( @name, 'T' ) = true()
      • used insted of true

  • XSL Explanation
  • Templates -- built-in templates, adding modularity, includes and imports
  • Templates Examples--
  • XSL Namespaces-- using namespaces with XSL
  • XPath -- getting around XSL
  • XPath Examples
  • Functions-- using functions
  • Functions Examples
  • Variables and Parameters