|
|
Plaçant le XSl variable
|
le stylesheet 1 et le stylesheet 3 montre les différentes manières de placer un xsl : variable, stylesheet 2 de XSLT et stylesheet 4 de XSLT de placer le xsl : param.
|
XML Source
<source>
<chapter>Chapter A</chapter>
<chapter>Chapter B</chapter>
<chapter>Chapter C</chapter>
<chapter>Chapter D</chapter>
</source>
|
Output 1
<TABLE>
<TR>
<TD>Chapter A (1/4)</TD>
</TR>
<TR>
<TD>Chapter B (2/4)</TD>
</TR>
<TR>
<TD>Chapter C (3/4)</TD>
</TR>
<TR>
<TD>Chapter D (4/4)</TD>
</TR>
</TABLE>
|
|
XSL stylesheet 1
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:variable name="totalChapters">
<xsl:value-of select="count(//chapter)"/>
</xsl:variable>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//chapter">
<TR>
<TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
XML Source
<source>
<chapter>Chapter A</chapter>
<chapter>Chapter B</chapter>
<chapter>Chapter C</chapter>
<chapter>Chapter D</chapter>
</source>
|
Output 2
<TABLE>
<TR>
<TD>Chapter A (1/4)</TD>
</TR>
<TR>
<TD>Chapter B (2/4)</TD>
</TR>
<TR>
<TD>Chapter C (3/4)</TD>
</TR>
<TR>
<TD>Chapter D (4/4)</TD>
</TR>
</TABLE>
|
|
XSL stylesheet 2
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:param name="totalChapters">
<xsl:value-of select="count(//chapter)"/>
</xsl:param>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//chapter">
<TR>
<TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
XML Source
<source>
<chapter>Chapter A</chapter>
<chapter>Chapter B</chapter>
<chapter>Chapter C</chapter>
<chapter>Chapter D</chapter>
</source>
|
Output 3
<TABLE>
<TR>
<TD>Chapter A (1/4)</TD>
</TR>
<TR>
<TD>Chapter B (2/4)</TD>
</TR>
<TR>
<TD>Chapter C (3/4)</TD>
</TR>
<TR>
<TD>Chapter D (4/4)</TD>
</TR>
</TABLE>
|
|
XSL stylesheet 3
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:variable name="totalChapters" select="count(//chapter)"/>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//chapter">
<TR>
<TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
XML Source
<source>
<chapter>Chapter A</chapter>
<chapter>Chapter B</chapter>
<chapter>Chapter C</chapter>
<chapter>Chapter D</chapter>
</source>
|
OutPut 4
<TABLE>
<TR>
<TD>Chapter A (1/4)</TD>
</TR>
<TR>
<TD>Chapter B (2/4)</TD>
</TR>
<TR>
<TD>Chapter C (3/4)</TD>
</TR>
<TR>
<TD>Chapter D (4/4)</TD>
</TR>
</TABLE>
|
|
XSL stylesheet 4
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:param name="totalChapters" select="count(//chapter)"/>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//chapter">
<TR>
<TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
Variables avec le même nom
|
Stylesheet peut faire ont plusieurs variables avec le même nom. Le stylesheet 1 de XSL démontre comment récupérer la valeur de la variable globale qui a le même nom que celui de le local. La valeur de la variable locale est liée au xsl : quand élément. Le reste du calibre voit donc seulement une variable globale.
|
XML Source
<source>
<chapter>Chapter A</chapter>
<chapter>Chapter B</chapter>
<chapter>Chapter C</chapter>
<chapter>Chapter D</chapter>
</source>
|
Output
<TABLE>
<TR>
<TD>First chapter : Chapter A</TD>
</TR>
<TR>
<TD>Chapter : Chapter B</TD>
</TR>
<TR>
<TD>Chapter : Chapter C</TD>
</TR>
<TR>
<TD>Last chapter : Chapter D</TD>
</TR>
</TABLE>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:variable name="text">Chapter</xsl:variable>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//chapter">
<TR>
<TD>
<xsl:variable name="text">
<xsl:choose>
<xsl:when test="position() = 1">First chapter</xsl:when>
<xsl:when test="position()=last()">Last chapter</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$text"/>
<xsl:text> : </xsl:text>
<xsl:value-of select="."/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|
|
Élément d'Avec-Param de XSL
|
Des paramètres pour le calibre peuvent être passés avec un xsl : élément d'avec-param. Si un calibre contient le xsl : élément de param ayant le même nom que celui d'un attribut nommé de xsl : l'avec-param, cette valeur est employé. Le stylesheet 1 de XSL montre l'exemple typique. Si vous voulez passer la variable, vous devriez devoir définir cette variable avec le xsl : élément de param. Regarder le stylesheet 2 de XSL pour l'approche fausse.
|
XML Source
<source>
<number>1</number>
<number>3</number>
<number>4</number>
<number>17</number>
<number>8</number>
</source>
|
Output
<TABLE>
<TR>
<TH>1 (odd)</TH>
</TR>
<TR>
<TH>3 (odd)</TH>
</TR>
<TR>
<TH>4 (even)</TH>
</TR>
<TR>
<TH>17 (odd)</TH>
</TR>
<TR>
<TH>8 (even)</TH>
</TR>
</TABLE>
|
|
XSL stylesheet 1
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//number">
<TR>
<TH>
<xsl:choose>
<xsl:when test="text() mod 2">
<xsl:apply-templates select=".">
<xsl:with-param name="type">odd</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</TH>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
<xsl:template match="number">
<xsl:param name="type">even</xsl:param>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>)</xsl:text>
</xsl:template>
</xsl:stylesheet>
|
XSL stylesheet 2
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE>
<xsl:for-each select="//number">
<TR>
<TH>
<xsl:choose>
<xsl:when test="text() mod 2">
<xsl:apply-templates select=".">
<xsl:with-param name="type">odd</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</TH>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
<xsl:template match="number">
<xsl:variable name="type">even</xsl:variable>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>)</xsl:text>
</xsl:template>
</xsl:stylesheet>
|
|
réglage du xsl : variable,
|
La variable peut tenir le fragment d'arbre de résultat. Les opérations qui sont autorisées sur le fragment d'arbre de résultat sont le sous-ensemble de ceux autorisés sur noeud-ont placé. L'opération est autorisée sur le fragment d'arbre de résultat seulement si cette opération devrait être autorisée sur la corde, opération sur la corde peut impliquer de convertir d'abord une corde en nombre ou booléen. En particulier, elle n'est pas autorisée pour employer « /, //, et [] » des opérateurs sur les fragments d'arbre de résultat. Quand l'opération autorisée est effectuée sur le fragment d'arbre de résultat, elle est exécutée exactement de la manière car elle serait sur un équivalent noeud-a placé.
|
XML Source
<source>
<TABLE border="1">
<TR>
<TD>AAA</TD>
<TD>BBB</TD>
</TR>
<TR>
<TD>aaa</TD>
<TD>bbb</TD>
</TR>
</TABLE>
<TABLE border="1">
<TR>
<TD>1111111</TD>
</TR>
<TR>
<TD>22222222</TD>
</TR>
</TABLE>
</source>
|
Output
<TABLE border="1">
<TR>
<TD>1111111</TD>
</TR>
<TR>
<TD>22222222</TD>
</TR>
</TABLE>
<TABLE border="1">
<TR>
<TD>AAA</TD>
<TD>BBB</TD>
</TR>
<TR>
<TD>aaa</TD>
<TD>bbb</TD>
</TR>
</TABLE>
<TABLE border="1">
<TR>
<TD>1111111</TD>
</TR>
<TR>
<TD>22222222</TD>
</TR>
</TABLE>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:variable name="A1">
<xsl:copy-of select="//TABLE[1]"/>
</xsl:variable>
<xsl:variable name="A2">
<xsl:copy-of select="//TABLE[2]"/>
</xsl:variable>
<xsl:template match="/">
<xsl:copy-of select="$A2"/>
<xsl:copy-of select="$A1"/>
<xsl:copy-of select="$A2"/>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
Keywords XSL Variables, XSL Variables, xslt variables, xsl variable, xslt variable, xsl for each,
xsl value of, asp net variables, asp net xsl, xpath variable, variables in xsl,
variable in xslt, variables in xslt, variable in xsl, variables xsl, xsl variable scope,
xsl set variable, xslt global variable, xsl variable value, xsl generate, xsl set,
functions variables, convert xsl, date variables, xsl multiple, include variables,
display variables, using variables, output variables, set variables, multiple variables,
xsl call, xslt parameters, xml parameters, xsl parameters, xml variable, xml variables
|