·  XSLT – Elements – <xsl:variable>


- Info :

  - Variable is global if it's declared as a top-level element, and local if it's declared within a template.

  - Value is defined by:

    - the content of the <xsl:variable> element, and then select attribute must not be defined

    - the select attribute, and then content must be empty: <xsl:variable name="prefix" select="'This is '"/>

    - default as empty string if both content and select attribute are not defined: <xsl:variable name="j"/>


- Example:



    <?xml version="1.0"?>

    <?xml-stylesheet type="text/xsl" href="test.xsl"?>












    <?xml version="1.0" ?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


      <xsl:variable name="prefix" select="'This is '"/>

      <xsl:variable name="scope"  select="."/>

      <xsl:variable name="suffix">




      <xsl:template match="/people/student/name">      

        <xsl:copy-of  select="$prefix"/>

        <xsl:value-of select="."/>

        <xsl:copy-of  select="$suffix"/>






    This is Jack

    This is Anton


- Other:

   <xsl:for-each select="/foo/bar">

     <xsl:variable name="some-bar" select="."/>

     <xsl:value-of select="$some-bar"/>