Use of global variables when XSL style parsing _xsl

Source: Internet
Author: User
Tags xsl

1. Remember first that the variable variable is only assigned once in the XSL, and it cannot be changed again. So how to call the variable, do not know draft experts are what to eat rice.

2. The so-called global, because the xsl:variable element is the xsl:stylesheet of the child, so the variables defined in stylesheet can be referenced throughout the instance space.
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:param name= "ViewType" select= "View"/>
<xsl:variable name= "Urlvariable" >
<xsl:choose>
<xsl:when test= "contains ($viewtype, ' edit ')" >
<xsl:text>/flowEngine/page1.wml</xsl:text>
</xsl:when>
<xsl:when test= "contains ($viewtype, ' View ')" >
<xsl:text>/flowEngine/page2.wml</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>/flowEngine/error.wml</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match= "/data" >
<xsl:value-of select = "$URLVariable"/>
<a href= "{$URLVariable}" > Myurl</a>
........... Is valid in the instance space
</xsl:template>
</xsl:stylesheet >
3. Reference method
1. Methods of $vairableName
For <xsl:value-of select = "$vairableName"/> such as elements with a node object value, use them.
However, the <xsl:text> $hyperURLVariable </xsl:text> is invalid.
Method of 2.{$vairableName}
For references with values other than the node, use {$vairableName}, and the braces on either side are not small.
such as <a href= "{$hyperURLVariable}" > Myurl</a>
But the <xsl:text>{$hyperURLVariable}</xsl:text> is also ineffective.
4. Error usage for global variables
Global variables defined
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:param name= "ViewType" select= "View"/>
<xsl:variable name= "urlvariable"/> <!---define a null value here-->
<xsl:template match= "/data" >
<xsl:choose>
<xsl:variable name= "Urlvariable" >
<xsl:when test= "contains ($viewtype, ' edit ')" >
<xsl:text>/flowEngine/page1.wml</xsl:text>
</xsl:when>
</xsl:variable>
<xsl:variable name= "Urlvariable" >
<xsl:when test= "contains ($viewtype, ' View ')" >
<xsl:text>/flowEngine/page2.wml</xsl:text>
</xsl:when>
</xsl:variable>
<xsl:variable name= "Urlvariable" >
<xsl:otherwise>
<xsl:text>/flowEngine/error.wml</xsl:text>
</xsl:otherwise>
</xsl:variable>
<!---The average person would think that this is a global variable assignment, and, in fact, it is in a smaller code space to redefine a local variable)
</xsl:choose>
<xsl:value-of select = "$URLVariable"/> <
<a href= "{$URLVariable}" > Myurl</a>
<!----the value of the global variable above is still empty, and you simply do not refer to the value of urlvariable in Xsl:choose, this error
And waste me three hours to get it---->
........... Global variables are valid throughout the instance space, except that we are not assigned the correct values.
</xsl:template>
</xsl:stylesheet >

Hope to see these, some help to you!

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.