嗨,我想获得具有类型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
让我检查它的工作原理.. –