Processar do condicional de XSL |
|
|
Processar do condicional de XSL
|
O xsl: se a instru��o permitir processar condicional. O Stylesheet 1 demonstra o exemplo t�pico de um xsl: para-cada uso, adicionando acima do texto entre as entradas individuais. Frequentemente voc� n�o quer adicionar acima o texto ap�s um �ltimo elemento. xsl-se a constru��o vier acess�vel aqui. (ver a 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>
|
|
The Choose Element
|
The xsl:choose element is used for the purpose of selection between the several
possibilities.
|
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
|