我有xml格式,它包含如下值的数组:
<xml total="446">
<document>
<id><![CDATA[binary:181-22559]]></id>
<language><![CDATA[[Croatian]]]></language>
<application><![CDATA[]]></application>
</document>
<document>
<id><![CDATA[binary:181-22559]]></id>
<language><![CDATA[[English]]]></language>
<application><![CDATA[[Outdoor, LED, Indoor, Signage]]]></application>
</document>
</xml>
当尝试使用xslt呈现上述xml时,我面临以下两个问题:1.它与方括号"["一起呈现2.我无法为逗号分隔的值创建单独的html元素。
以下是我的xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<hr class="grid-hr inner-grid"/>
<fieldset>
<legend>%%filter_document_language%%:</legend>
<label class="visuallyhidden" for="document-language">Language:</label>
<select id="document-language">
<option value="All" selected="selected">All</option>
<xsl:if test="/xml/document/language/text()">
<xsl:for-each select="xml/document">
<xsl:sort select="language"/>
<xsl:if test="language/text()">
<xsl:variable name="lastLanguage" select="language"/>
<xsl:if test="not(preceding-sibling::document[language=$lastLanguage])">
<xsl:variable name="language">
<xsl:value-of select="language"/>
</xsl:variable>
<option value="{$language}" selected=""><xsl:copy-of select="$language" /></option>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:if>
</select>
</fieldset>
<hr class="grid-hr inner-grid"/>
<fieldset>
<legend>%%filter-by-application%%:</legend>
<ul class="itembrowser-filter">
<xsl:for-each select="xml/document">
<xsl:sort select="application"/>
<xsl:if test="application/text()">
<xsl:variable name="lastApplication" select="application"/>
<xsl:if test="not(preceding-sibling::document[application=$lastApplication])">
<xsl:variable name="application">
<xsl:value-of select="application"/>
</xsl:variable>
<li>
<label>
<input type="checkbox" class="input-big-checkbox" name="application-filter" value="{$application}"/>
<span class="label"><xsl:copy-of select="$application" /></span>
</label>
</li>
</xsl:if>
</xsl:if>
</xsl:for-each>
</ul>
</fieldset>
</xsl:template>
</xsl:stylesheet>
我的预期输出应该如下:
<hr class="grid-hr inner-grid">
<fieldset>
<legend>Filter by Document Language:</legend>
<label class="visuallyhidden" for="document-language">Language:</label>
<select id="document-language">
<option value="All" selected="selected">All</option>
<option value="Croatian" selected="">Croatian</option>
<option value="English" selected="">English</option>
</select>
</fieldset>
<hr class="grid-hr inner-grid">
<fieldset>
<legend>Filter by Application:</legend>
<ul class="itembrowser-filter">
<li>
<label>
<input type="checkbox" class="input-big-checkbox" name="application-filter" value="Outdoor">
<span class="label">Outdoor</span>
</label>
<label>
<input type="checkbox" class="input-big-checkbox" name="application-filter" value="LED]">
<span class="label">LED</span>
</label>
<label>
<input type="checkbox" class="input-big-checkbox" name="application-filter" value="Indoor">
<span class="label">Indoor</span>
</label>
<label>
<input type="checkbox" class="input-big-checkbox" name="application-filter" value="Signage">
<span class="label">Signage</span>
</label>
</li>
</ul>
</fieldset>
如果有人能帮我,那就太好了。
- 它与方括号"["一起呈现
这些方括号是您的数据的一部分。您的数据提供商似乎不了解如何标记CDATA。在他们学会之前,你必须自己去掉多余的括号,例如替换:
<xsl:value-of select="language"/>
带有:
<xsl:value-of select="translate(language, '[]', '')"/>
或:
<xsl:value-of select="substring(language, '2', string-length(language) - 2)"/>
关于您的第二个问题,我建议您结合XSLT1.0搜索"标记化"。如果你无法从以前的帖子中找到答案,那就发布一个单独的问题。还要注意,您的特定处理器可能支持EXSLT str:tokenze()扩展函数,从而避免了对递归命名模板的需要。
我还建议你读一读穆恩钦分组。