Traitement de conditionnel de XSL |
|
|
Traitement de conditionnel de XSL
|
Le xsl : si l'instruction permet le traitement conditionnel. Le Stylesheet 1 d�montre le cas typique d'un xsl : pour-chaque utilisation, s'ajoutant vers le haut du texte entre les diff�rentes entr�es. Souvent vous ne voulez pas ajouter le texte apr�s un dernier �l�ment. xsl-si la construction vient maniable ici. (voir � Stylesheet 2)
|
XML source
<?xml version="1.0"?>
<xslTutorial >
<list>
<entry name="A"/>
<entry name="B"/>
<entry name="C"/>
<entry name="D"/>
</list>
</xslTutorial>
|
HTML output 1
<HTML>
<HEAD> </HEAD>
<BODY> A, B, C, D,
</BODY>
</HTML>
|
HTML output 2
<HTML>
<HEAD> </HEAD>
<BODY> A, B, C, D
</BODY>
</HTML>
|
|
XSL stylesheet 1
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:template match="list">
<xsl:for-each select="entry">
<xsl:value-of select="@name"/>
<xsl:text> , </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
|
XSL stylesheet 2
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="list">
<xsl:for-each select="entry">
<xsl:value-of select="@name"/>
<xsl:if test="not(position()=last())">
<xsl:text> , </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
|
|
L'�l�ment de choix
|
Le xsl : choisir l'�l�ment est employ� afin du choix entre les multiples possibilit�s.
|
XML source
<?xml version="1.0"?>
<xslTutorial >
<SECTION>
<DATA>I need a pen.</DATA>
<DATA>I need some paper.</DATA>
<SUMMARY>I need a pen and some paper</SUMMARY>
</SECTION>
<SECTION>
<DATA>I need bread.</DATA>
<DATA>I need butter.</DATA>
</SECTION>
</xslTutorial>
|
HTML output 1
<HTML>
<HEAD> </HEAD>
<BODY>
<P>SUMMARY: I need a pen and some paper</P>
<P>DATA: I need bread.</P>
<P>DATA: I need butter.</P>
</BODY>
</HTML>
|
|
XSL stylesheet 1
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:template match="//SECTION">
<xsl:choose>
<xsl:when test='SUMMARY'>
<P><xsl:text> SUMMARY: </xsl:text>
<xsl:value-of select="SUMMARY"/></P>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="DATA">
<P><xsl:text> DATA: </xsl:text>
<xsl:value-of select="."/></P>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
Keywords XSL Conditional processing, xsl processor, xsl id, xsl output, xsl date, c# condit,
xsl dom, xsl fo, docbook xsl, c# xsl, xsl parser, xsl transformation, svg xsl,
xsl tree, xalan xsl, msxml xsl, string xsl, xsl tag, conditional select, conditional function,
display xsl, conditional if, value xsl, xsl using, conditional syntax, convert xsl
|