Elaborazione di condizionale di XSL |
|
|
Elaborazione di condizionale di XSL
|
Il xsl: se l'istruzione permette l'elaborazione condizionale. Lo Stylesheet 1 dimostra il caso tipico di un xsl: per-ogni uso, aggiungente sul testo fra le diverse entrate. Non desiderate spesso aggiungere in su il testo dopo un ultimo elemento. xsl-se la costruzione viene pratico qui. (vedere 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>
|
|
L'elemento di scelta
|
Il xsl: scegliere l'elemento � usato a scopo della selezione fra le parecchie possibilit�.
|
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
|