嗨,我想獲得具有類型html的文件。我很好。但我的問題,當沒有文件與HTML它顯示爲空。但我想顯示一些消息,如「沒有提交htmls」。我會在正常的編程語言中使用計數器變量。在這裏我無法做到這一點,請幫我解決這個問題。謝謝xslt中的計數器變量功能
注意:需要xslt 1.0。
XML:
<?xml version="1.0" encoding="UTF-8"?>
<Files>
<Path class="com.interwoven.cssdk.filesys.CSAreaRelativePath" path="MS/homedemo.html" type="html" />
<Path class="com.interwoven.cssdk.filesys.CSAreaRelativePath" path="MS/test125.html" type="html" />
<Path class="com.interwoven.cssdk.filesys.CSAreaRelativePath" path="iwov-resources/css/akz.css" type="css" />
<Path class="com.interwoven.cssdk.filesys.CSAreaRelativePath" path="iwov-resources/css/animate.css" type="css" />
<Path class="com.interwoven.cssdk.filesys.CSAreaRelativePath" path="iwov-resources/css/base.css" type="css" />
<Path class="com.interwoven.cssdk.filesys.CSAreaRelativePath" path="iwov-resources/css/font-awesome-ie7.css" type="css" />
</Files>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<p>
<xsl:apply-templates select="//Files" />
</p>
</html>
</xsl:template>
<xsl:template match="//Files">
<h1 style="background: #979797;border-radius: 5px;color: #FFF;text-shadow: 1px 1px 1px #000;padding: 5px;font-size:16px;">US files are now live and you can access them using the following URLs:</h1>
<ol>
<xsl:for-each select="//Files/Path">
<xsl:variable name="type">
<xsl:choose>
<xsl:when test="@type">
<xsl:value-of select="@type" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'html'" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="path" select="@path" />
<xsl:choose>
<xsl:when test="$type='html'">
<li>
<a class="iw-base-link">
<xsl:attribute name="href">
<xsl:value-of select="$path"/>
</xsl:attribute>
<xsl:value-of select="$path" />
</a>
</li>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</ol>
</xsl:template>
</xsl:stylesheet>
當我們有類型的HTML文件,然後顯示在下面的事情:
US files are now live and you can access them using the following URLs:
1.MS/homedemo.html
2.MS/test125.html
當我們沒有類型的HTML文件,然後顯示在下面的事情:
US files are now live and you can access them using the following URLs:
NO html files were submitted.
它是xslt 1.0版本 –
@susheel是的。 – parakmiakos
讓我檢查它的工作原理.. –