..." />
<xsl:template match="entertainment">
<!-- здесь $movie = 'Mr. Blandings Builds His Dream House'-->
<xsl:variable name="movie" select="'Goldfinger'"/>
<!-- здесь $movie = 'Goldfinger'-->
<xsl:variable name="movie" select="'Withnail and I'"/><!-- Запрещено -->
</xsl:template>
<!-- здесь $movie = 'Mr. Blandings Builds His Dream House'-->
.
.
.
Глобальные переменные тоже нельзя объявлять повторно:
<xsl:variable name="movie" select="'Mr. Blandings Builds His Dream House'"/>
<!-- здесь $movie = 'Mr. Blandings Builds His Dream House'-->
<xsl:template match="entertainment">
<!-- здесь $movie = 'Mr. Blandings Builds His Dream House"-->
<xsl:variable name="movie" select="'Goldfinger'"/>
<!-- здесь $movie = 'Goldfinger'-->
<xsl:variable name="movie" select="'Withnail and I'"/><!-- Запрещено -->
</xsl:template>
<!-- здесь $movie = 'Mr. Blandings Builds His Dream House'-->
<xsl:variable name="movie" select="'Goldfinger'"/><!-- Запрещено -->
Несмотря на все эти ограничения, вы можете менять значение переменной на каждом шаге цикла <xsl:for-each>, как мы увидим в следующем разделе.
Работа с переменными
Давайте рассмотрим примеры применения переменных. В следующем примере (листинг 9.1) я присваиваю переменной copyright сообщение об авторских правах и затем с ее помощью добавляю атрибут copyright во все элементы planets.xml.
<?xml version="1.0"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:variable name="copyright" select="'(c)2002 Starpowder Inc.'"/>
<xsl:template match="*">