Aug 18, 2007

xslt variable

You can build a variable by using select like below.

            
            

Or you can build a variable using constructor like below

            
            
            
            
            
            
            
            

            
            

This is demo

If a variable initialized by a select course, it contains a set of nodes. You can use the variable as a node. For example,

            
            

            
            
            

If you are using constructor to build a constructor, the variable can hold any arbitrary content, this content is called result tree fragment. You can imagine a result tree fragment (RTF) as a fragment or a chunk of XML code. You can assign a result tree fragment to a variable directly, or result tree fragment can arise from applying templates or other XSLT instructions. The following code assigns a simple fragment of XML to the variable $author.

            
            Jirka
            Kosek
            jirka@kosek.cz
            
            

Now let's say we want to extract the e-mail address from the $author variable. The most obvious way is to use an expression such as $author/email. But this will fail, as you can't apply XPath navigation to a variable of the type "result tree fragment."

            
            ...
            
            
            ...
            
            

If you want to reuse the content of result tree, you can put copy-of statement to where you want your output to be.